4.10 实战案例——分布式部署LNMP+WordPress

来自CloudWiki
跳转至: 导航搜索

分布式LNMP环境的调试

配置Nginx服务支持PHP环境

[root@nginx~]# vi /usr/local/nginx/conf/nginx.conf (编辑这个配置文件,找到下面的部分并修改)

  location/{
             root      /www;                                #更改网页目录
             index     index.php index.html index.htm;      #添加index.php         
             }
  1. 去掉location{}前的注释符
  location~ l.phps {
                 root       /www;                          #更改目录为/www
                 fastcgi_pass 192.168.128.144:9000;        #注意:在这里添加PHP主机ip地址

IP地址

                 fastcgi_index     index.php;
                 fastcgi_param SCRIPT_FILENAME/scriptsfastcgi_script_name;
                 include           fastcgi_params;
                   }

修改之后,在/usr/local/nginx/conf/fastcgi params添加配置,命令如下:

  [root@nginx~]# vi /usr/local/nginx/conf/fastcgi_params
  fastcgi_param SCRIPT_NAME           $fastcgi_script_name;
  fastcgi_param  SCRIPT_FILENAME      $document_root$fastcgi_script_name;#添加这行代码
  fastcgi_param REQUEST_URI           $request_uri;

创建目录

在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

先将压缩包上传到虚拟机

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配置文件

  [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', '000000');
  /**MySQL主机*/
  define('DB_HOST', '192.168.200.30');
  /**创建数据表时默认的文字编码*/
  define('DB_CHARSET', 'utf8');
  /**数据库整理类型。如不确定请勿更改*/
  define('DB_COLLATE',");
  ...省略...

将该配置文件scp至php节点的/www目录下,命令如下:

[root@nginx ~]# scp /www/wp-config.php root@192.168.200.60:/www/

创建WordPress数据库

在mysqll节点,登录数据库,使用命令创建WordPress数据库,命令如下:

[root@mysqll ~]# mysql -uroot -p000000

  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 'lc' 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.50地址进行访问,会出现著名的WordPress五分钟安装程序,填写必要的信息,然后单击左下角“安WordPress”按钮,进行WordPress应用的安 装。

至此,分布式部署LNMP+WordPress应用已完成。