LNMP项目实战-WordPress站点搭建
Posted y_zilong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LNMP项目实战-WordPress站点搭建相关的知识,希望对你有一定的参考价值。
LNMP项目实战:
L:Linux (centos 7.9)
N:nginx ( 1.18.0)
M:mysql(5.7.30)
P:php ( 7.4.19)
部署规划:nginx php-fpm 运行web服务,mysql存储
二进制源码包目录:/apps/
数据目录:/data/
1、二进制部署Mysql数据库
1、上传包解压
[root@yzil ~]# ls
mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
[root@yzil ~]# tar xf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
[root@yzil ~]# mkdir /apps
[root@yzil ~]# mv mysql-5.7.30-linux-glibc2.12-x86_64 /apps/mysql
[root@yzil ~]# cd /apps/
[root@yzil apps]# ls
mysql
2、配置环境变量
[root@yzil apps]# vi /etc/profile.d/mysql.sh
export PATH=/apps/mysql/bin:$PATH
[root@yzil apps]# source /etc/profile.d/mysql.sh
3、配置数据目录和权限
[root@yzil ~]# mkdir -p /data/mysql
[root@yzil ~]# useradd -s /sbin/nglogin mysql
[root@yzil ~]# chown mysql.mysql /data/mysql
[root@yzil ~]# chown -R mysql.mysql /apps/mysql
4、初始化
[root@yzil ~]# mysqld --initialize --user=mysql --basedir=/apps/mysql --datadir=/data/mysql
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
[root@yzil ~]# yum install -y libaio
[root@yzil ~]# mysqld --initialize --user=mysql --basedir=/apps/mysql --datadir=/data/mysql
2021-05-28T01:49:48.868392Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-28T01:49:51.395018Z 1 [Note] A temporary password is generated for root@localhost: ejy#o+CyL1+C
#:后面密码记住
5、定义配置文件
[root@yzil ~]# cat /etc/my.cnf
[mysqld]
user=mysql
basedir=/apps/mysql
datadir=/data/mysql
server_id=1
port=3306
socket=/tmp/mysql.sock
log-error=/var/log/mysql/mysql.log
character-set-server=utf8mb4
[mysql]
socket=/tmp/mysql.sock
default-character-set=utf8mb4
prompt="\\\\r:\\\\m:\\\\s(\\\\u@\\\\h) [\\\\d]>\\\\_"
[root@yzil ~]#
#创建日志目录,并修改权限
[root@yzil ~]# mkdir /var/log/mysql
[root@yzil ~]# chown mysql.mysql /var/log/mysql
6、启动
[root@yzil ~]# cd /apps/mysql/support-files/
[root@yzil support-files]# ./mysql.server start
Starting MySQL. [ OK ]
[root@yzil support-files]# ss -nlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 80 [::]:3306 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
[root@yzil support-files]#
[root@yzil ~]# mysql -uroot -p'ejy#o+CyL1+C'
10:30:16(root@localhost) [(none)]> alter user root@'localhost' identified by 'redhat';
Query OK, 0 rows affected (0.00 sec)
[root@yzil ~]# mysql -uroot -predhat
7、开机启动,编写systemd配置文件
[root@yzil ~]# cd /apps/mysql/support-files/
[root@yzil support-files]# ./mysql.server stop
Shutting down MySQL.. [ OK ]
[root@yzil ~]# vi /etc/systemd/system/mysqld.service
[root@yzil ~]# cat /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/apps/mysql/bin/mysqld --defaults-file=/etc/my.cnf
[root@yzil ~]# systemctl enable --now mysqld
8、创建数据库并授权
mysql> create database wordpress;
mysql> grant all privileges on wordpress.* to "wordpress"@'8.129.85.%' identified by 'redhat';
mysql> flush privileges;
2、编译安装nginx
[root@yzil ~]# yum install -y gcc gcc-c++ pcre pcre-devel pcre pcre-devel zlib zlib-devel automake make openssl openssl-devel
[root@yzil ~]# tar -xf nginx-1.18.0.tar.gz
[root@yzil ~]# mv nginx-1.18.0 /apps/nginx
[root@yzil ~]# useradd -s /sbin/nologin nginx
[root@yzil ~]# chown -R nginx.nginx /apps/nginx
[root@yzil ~]# cd /apps/nginx/
[root@yzil nginx]# ./configure --prefix=/data/nginx \\
> --user=nginx --group=nginx \\
> --with-http_ssl_module \\
> --with-http_stub_status_module
[root@yzil nginx]# make && make install
[root@yzil nginx]# /data/nginx/sbin/nginx -t
nginx: the configuration file /data/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /data/nginx/conf/nginx.conf test is successful
[root@yzil nginx]#
#配置环境变量
[root@yzil ~]# vi /etc/profile.d/nginx.sh
export PATH=$PATH:/data/nginx/sbin
[root@yzil ~]# source /etc/profile.d/nginx.sh
3、编译安装php
[root@yzil ~]# yum install -y libxml2 libxml2-devel
[root@yzil ~]# yum install -y libcurl libcurl-devel
[root@yzil ~]# yum install sqlite-devel
[root@yzil ~]# tar -xf php-7.4.19.tar.gz
[root@yzil ~]# mv php-7.4.19 /apps/php
[root@yzil php]# ./configure --prefix=/data/php \\
> --enable-fpm \\
> --with-config-file-path=/data/php/conf \\
> --with-zlib --with-curl \\
> --enable-mysqlnd \\
> --with-pdo-mysql=mysqlnd \\
> --with-mysqli=mysqlnd \\
> --with-openssl-dir \\
> --disable-fileinfo
[root@yzil php]# make && make install
#配置环境变量
[root@yzil ~]# vi /etc/profile.d/php.sh
export PATH=$PATH:/data/php/bin
[root@yzil ~]# source /etc/profile.d/php.sh
4、配置nginx
[root@yzil ~]# vi /data/nginx/conf/nginx.conf
server {
listen 80;
server_name 8.129.85.235;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /data/nginx/wordpress;
index index.php index.html index.htm;
}
location ~ \\.php$ {
root /data/nginx/wordpress;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#隐藏nginx的版本号
[root@yzil ~]# vi /data/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
server_tokens off; #添加这一行,隐藏nginx的版本号
}
5、配置PHP
[root@yzil ~]# cp /data/php/php.ini-production /data/php/etc/php.ini
[root@yzil ~]# cd /data/php/etc/php-fpm.d/
[root@yzil php-fpm.d]# cp www.conf.default www.conf
[root@yzil php-fpm.d]# vi www.conf
user = nginx
group = nginx
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
pm.status_path= /pm_status
ping.path= /ping
ping.response= pong
[root@yzil etc]# cp php-fpm.conf.default php-fpm.conf
[root@yzil etc]# mkdir /data/php/log/ #日志文件路径
#检查语法并启动php-fpm:
[root@yzil ~]# /data/php/sbin/php-fpm -t
[30-May-2021 21:45:26] NOTICE: configuration file /data/php/etc/php-fpm.conf test is successful
[root@yzil ~]#
#验证php-fpm:
[root@yzil ~]#/data/php/sbin/php-fpm -c /data/php/etc/php.ini
#php自带的开机启动配置文件
[root@yzil ~]# cp /apps/php/sapi/fpm/php-fpm.service /usr/lib/systemd/system/
[root@yzil ~]# vi /data/php/etc/php.ini
expose_php = OFF #不暴露版本号
upload_max_filesize = 200M #最大上传文件
post_max_size = 800M #最大上传数据大小
4、安装wordpress
[root@yzil ~]#tar -xf latest-zh_CN.tar.gz -C /data/nginx/
[root@yzil ~]#chown -R nginx.nginx /data/nginx/
以上是关于LNMP项目实战-WordPress站点搭建的主要内容,如果未能解决你的问题,请参考以下文章
Nginx 实践案例(源码编译安装方式):利用LNMP搭建wordpress站点