实现LNMP架构,并部署WordPress以及配置NGINX虚拟主机

1、编译安装LNMP,并安装wordpress

1.1 安装php, php-mysql,myql,php-fpm

[ ~]# yum install  php php-mysql ngnix  mariadb-server php-fpm -y

1.2 编译安装nginx

1.2.1 安装依赖包

[ nginx]# yum install gcc pcre-devel openssl-devel zlib-devel -y

1.2.2 创建nginx用户

[ ~]# useradd -r -s /sbin/nologin nginx

1.2.3 官网下载nginx源码包,并解压,编译安装

[ src]# pwd
/usr/local/src
[ src]# ls
nginx-1.16.1.tar.gz
[ src]# tar xf nginx-1.16.1.tar.gz 
[ src]# ls
nginx-1.16.1  nginx-1.16.1.tar.gz
[ src]# mv nginx-1.16.1 nginx
[ src]# cd nginx/
[ nginx]# ls
auto     CHANGES.ru  configure  html     man     src
CHANGES  conf        contrib    LICENSE  README
[ nginx]# ./configure --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_dav_module --with-http_stub_status_module --with-threads --with-file-aio
[ nginx]# make -j 4 && make install

1.2.4 配置环境变量,方便启动nginx

[ sbin]# export PATH="/usr/local/nginx/sbin:$PATH"

1.2.5 修改nginx配置文件,使fstcgi处理.php后缀的网页

[ nginx]# vim /usr/local/nginx/conf/nginx.conf  ###在配置文件增加如下一行
include       /usr/local/nginx/conf.d/*.conf;
[ conf.d]# pwd
/usr/local/nginx/conf.d
[ conf.d]# cat wordpress.conf 
server {
        listen       80;
        server_name  www.zhuweijun.com;
        root /data/php;
        index index.php;
        location ~* \.php$ {
                root /data/php;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

1.2.6 创建相应目录并启动NGINX和php-fpm服务

[ nginx]# mkdir /data/php
[ nginx]# systemctl start php-fpm   ###启动php-fpm服务
[ nginx]# nginx    ###启动nginx服务

1.3 在数据库服务器新建wpdb库和wpuser远程连接用户

[ ~]# systemctl start mariadb
[ ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> create database wpdb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on wpdb.* to ‘%‘ identified by "wppass";
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
###测试远程连接数据库
[ nginx]# mysql_secure_installation ##跑下安全加固脚本
[ ~]# mysql -uwpuser -pwppass -hc1
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]>

1.4 官网下载并解压缩WordPress博客程序到网页站点目录下并准备wordpress配置文件

[ php]# pwd
/data/php
[ php]# ls
wordpress  wordpress-5.0.3-zh_CN.zip
[ php]# mv wordpress/* .
[ php]# ls
index.php                  wp-blog-header.php    wp-load.php
license.txt                wp-comments-post.php  wp-login.php
readme.html                wp-config-sample.php  wp-mail.php
wordpress                  wp-content            wp-settings.php
wordpress-5.0.3-zh_CN.zip  wp-cron.php           wp-signup.php
wp-activate.php            wp-includes           wp-trackback.php
wp-admin                   wp-links-opml.php     xmlrpc.php
[ php]# cp -r * /data/nginx/
###准备wordpress配置文件
[ php]# cp wp-config-sample.php wp-config.php
[ php]# vim wp-config.php
define(‘DB_NAME‘, ‘wpdb‘);

/** MySQL数据库用户名 */
define(‘DB_USER‘, ‘wpuser‘);

/** MySQL数据库密码 */
define(‘DB_PASSWORD‘, ‘wppass‘);

1.5 设置wordpress目录权限

[ html]#  setfacl -R -m u:nginx:rwx /data

1.6 修改Windows系统的host文件

C:\Windows\System32\drivers\etc\hosts
编辑hosts文件,增加如下一行:
10.0.1.242 www.zhuweijun.com admin.zhuweijun.com

1.7 在浏览器打开http://www.zhuweijun.com进行页面安装
实现LNMP架构,并部署WordPress以及配置NGINX虚拟主机
实现LNMP架构,并部署WordPress以及配置NGINX虚拟主机
实现LNMP架构,并部署WordPress以及配置NGINX虚拟主机
实现LNMP架构,并部署WordPress以及配置NGINX虚拟主机
实现LNMP架构,并部署WordPress以及配置NGINX虚拟主机

2、配置虚拟主机,www.x.com域名实现首页访问,admin.x.com域名实现wordpress的后台访问。
2.1 在第1节的基础上修改nginx的配置文件

[ conf.d]# pwd
/usr/local/nginx/conf.d
[ conf.d]# cat wordpress.conf 
server {
        listen       80;
        server_name  www.zhuweijun.com;
        root /data/php;
        index index.php;
        location ~* \.php$ {
                root /data/php;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

server {
        listen       80;
        server_name  admin.zhuweijun.com;
        root /data/php;
        index wp-login.php;
        location ~* \.php$ {
                root /data/php;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

2.2 测试

#重新加载nginx配置
[ conf.d]# nginx -s reload

实现LNMP架构,并部署WordPress以及配置NGINX虚拟主机
实现LNMP架构,并部署WordPress以及配置NGINX虚拟主机

相关推荐