分布式部署LNMP+WordPress
| IP | 主机名 | 节点 |
| 192.168.200.30 | mysql1 | 数据库主节点 |
| 192.168.200.40 | mysql2 | 数据库从节点 |
| 192.168.200.50 | nginx | Nginx服务节点 |
| 192.168.200.60 | php | PHP环境节点 |
一 配置Nginx服务支持PHP环境
用 Xshell 连接到192.168.200.50虚拟机(nginx节点),并进行修改配置文件的操作
[root@nginx ~]# vi /usr/local/nginx/conf/nginx.conf
…省略…
location / {
root /www; #更改网页目录
index index.php index.html index.htm; #添加index.php
}
…省略…
location ~ \.php$ { #去掉location{}前的注释符
root /www; #更改目录为/www
fastcgi_pass 192.168.233.27:9000; #注意:在这里添加PHP主机IP地址
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
…省略…
修改完毕后,保存退出
接着在/usr/local/nginx/conf/fastcgi_params添加配置
[root@nginx ~]# vi /usr/local/nginx/conf/fastcgi_params
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #添加这行代码
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
二 创建目录
在nginx和php节点,创建/www目录,并修改用户和用户组
nginx节点:
[root@nginx ~]# mkdir /www
[root@nginx ~]# chown nginx:nginx /www/
php节点:
[root@php ~]# mkdir /www
[root@php ~]# chown nginx:nginx /www/
三 部署WordPress
两个节点,使用远程传输工具,将提供的wordpress-4.7.3-zh_CN.zip压缩包上传至nginx节点和php节点的/root目录下并解压,将解压后的文件复制到/www目录(unzip命令不能使用时,请自行使用YUM源安装unzip工具)
nginx节点:
[root@nginx ~]# unzip wordpress-4.7.3-zh_CN.zip
[root@nginx ~]# mv wordpress/* /www/
php节点:
[root@php ~]# unzip wordpress-4.7.3-zh_CN.zip
[root@php ~]# mv wordpress/* /www/
在nginx节点,修改WordPress应用的配置文件,WordPress应用提供了wp-config-sample.php模版文件,将模板文件复制为wp-config.php,并修改
[root@nginx ~]#cp /www/wp-config-sample.php /www/wp-config.php
[root@nginx ~]# vi /www/wp-config.php
…省略…
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wordpress');
/** MySQL数据库用户名 */
define('DB_USER', 'root');
/** MySQL数据库密码 */
define('DB_PASSWORD', '123456');
/** MySQL主机 */
define('DB_HOST', '192.168.233.30');
/** 创建数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8');
/** 数据库整理类型。如不确定请勿更改 */
define('DB_COLLATE', '');
…省略…
按照上述文件修改配置文件,保存退出后,将该配置文件scp至php节点的/www目录下
[root@nginx ~]# scp /www/wp-config.php root@192.168.233.27:/www/
四 创建WordPress数据库
在mysql1节点,登录数据库,使用命令创建WordPress数据库
[root@mysql1 ~]# mysql -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.44-MariaDB-log MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> Ctrl-C -- exit!
Aborted
五 验证WordPress应用
在Nginx节点重启Nginx服务
[root@nginx ~]# nginx -s reload
在浏览器中输入192.168.200.30地址进行访问,会出现著名的WordPress五分钟安装程序,填写必要的信息,然后单击左下角“安装WordPress”按钮,进行WordPress应用的安装

进入WordPress后台界面

单击左上角的“myblog”图标,进入WordPress首页


浙公网安备 33010602011771号