利用LNMP实现wordpress站点搭建
阅读原文时间:2023年07月09日阅读:2

一、部署MySQL

# 准备用户,依赖包,二进制程序
[root@nginx ~]# yum install -y libaio perl-Data-Dumper autoconf
[root@nginx ~]# groupadd -r mysql
[root@nginx ~]# useradd -r -g mysql -d /data/mysql mysql
[root@nginx ~]# mkdir -p /data/mysql
[root@nginx ~]# chown -R mysql.mysql /data/mysql
[root@nginx ~]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz
[root@nginx ~]# tar xvf mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz  -C /usr/local

[root@nginx ~]# cd /usr/local
[root@nginx local]# ln -sv mysql-5.6.51-linux-glibc2.12-x86_64/ mysql
[root@nginx local]# chown -R mysql.mysql /usr/local/mysql/
[root@nginx local]# cd mysql
[root@nginx mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql/
[root@nginx mysql]# ls /data/mysql/ -l    #检验数据文件是否生成
total 110604
-rw-rw---- 1 mysql mysql 12582912 Jun 1 16:44 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Jun 1 16:44 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Jun 1 16:44 ib_logfile1
drwx------ 2 mysql mysql 4096 Jun 1 16:44 mysql
drwx------ 2 mysql mysql 4096 Jun 1 16:44 performance_schema
drwx------ 2 mysql mysql 4096 Jun 1 16:44 test
[root@nginx ~]# cat > /etc/my.cnf <<EOF
[mysqld]
user=mysql
datadir=/data/mysql
socket=/data/mysql/mysql.sock
innodb_file_per_table=on
skip_name_resolve = on        

[client]
port=3306
socket=/data/mysql/mysql.sock

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/data/mysql/mysql.pid
EOF

[root@nginx ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@nginx ~]# chkconfig --add mysqld && chkconfig mysqld on
[root@nginx ~]# service mysqld start
[root@nginx ~]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@nginx ~]# . /etc/profile.d/mysql.sh


mysql> create database wordpress;
mysql> create user wordpress@'10.0.0.%' identified by '123456';
mysql> grant all on wordpress.* to wordpress@'10.0.0.%';

二、部署PHP

[root@nginx ~]# yum -y install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel
[root@nginx ~]# tar xf php-7.4.27.tar.gz
[root@nginx ~]# cd php-7.4.27/
[root@nginx php-7.4.27]# ./configure \
--prefix=/apps/php \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-zlib \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-mbstring \
--enable-xml \
--enable-sockets \
--enable-fpm \
--enable-maintainer-zts \
--disable-fileinfo
[root@nginx ~]# make -j 4 && make install
[root@nginx ~]# echo 'PATH=/apps/php/bin:/apps/httpd/bin:$PATH' > /etc/profile.d/php.sh
[root@nginx ~]# . /etc/profile.d/php.sh


[root@nginx php-7.4.27]# cp php.ini-production /etc/php.ini
[root@nginx php-7.4.27]# cd /apps/php/etc && cp php-fpm.conf.default php-fpm.conf
[root@nginx etc]# cd php-fpm.d/ && cp www.conf.default www.conf
[root@nginx etc]# vim www.conf
[www]
user = www
group = www
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.status_path = /pm_status
ping.path = /ping
access.log = log/$pool.access.log
slowlog = log/$pool.log.slow

[root@nginx ~]# useradd -r -s /sbin/nologin www    #创建用户
[root@nginx ~]# mkdir /apps/php/log        #创建访问日志文件路径


[root@nginx ~]# /apps/php/sbin/php-fpm -t
[root@nginx ~]# cp php-7.4.27/sapi/fpm/php-fpm.service /usr/lib/systemd/system/
[root@nginx ~]# systemctl daemon-reload && systemctl enable --now php-fpm
[root@nginx ~]# ss -ntl    #9000端口一打开

三、部署NGINX

请查阅编译安装nginx

[root@nginx ~]# cat /apps/nginx/conf/nginx.conf
worker_processes 1;
pid /apps/nginx/run/nginx.pid;
events {
    worker_connections 1024;
}
http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;
    server {
        listen 80;
        server_name www.magedu.org;
        location / {
            root /data/nginx/wordpress;
            index index.php index.html index.htm;
        }
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }
        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;
        }
        location ~ ^/(ping|pm_status)$ {
            include fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
        }
    }
}



[root@nginx ~]# mkdir -p /data/nginx/wordpress
[root@nginx ~]# vim /data/nginx/wordpress/test.php
<?php
phpinfo();
?>

测试

四、部署WordPress

##4.1 准备wordpress文件
# tar xf latest-zh_CN.tar.gz
# cp -r wordpress/* /data/nginx/wordpress
# chown -R www.www /data/nginx/wordpress/