安装要求:

                (1) 三者分离于三台主机

                (2) 一个虚拟主机用于提供phpMyAdmin;另一个虚拟主机用于提供wordpress;

            (3) xcache


    

         IP    系统             软件

     192.168.1.103

   CentOS 7             httpd
     192.168.1.104   CentOS 7       php-fpm,php-mysql,,xcache
     192.168.1.105   CentOS 7             mariadb




  1192.168.1.103 安装配置httpd


    1)安装配置httpd


    [root@localhost ~]# yum install httpd -y

     [root@localhost ~]# vim /etc/httpd/conf/httpd.conf


     #DocumentRoot "/var/www/html"  //注释web默认访问路径


      [root@localhost ~]# mkdir /apps/vhosts/b.net -pv //创建虚拟主机wordpress访问页面

     [root@localhost ~]# mkdir /apps/vhosts/c.org -pv //创建虚拟主机phpMyAdmin访问页面


    2)基于虚拟主机配置


     [root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf //创建并配置虚拟主机的配置文件

    

     CentOS 7系统之 lamp (php-fpm)详解_php




  2、192.168.1.104安装配置 php-fpm ,php-mysql


   1)安装配置php-fpm


      [root@localhost ~]# rpm -q php   //确保没有装载php包

      package php is not installed

      [root@localhost ~]# yum install php-fpm php-mysql php-mbstring -y


      [root@localhost ~]# vim /etc/php-fpm.d/www.conf

      listen = 192.168.1.104:9000  //修改php服务器监听地址

      listen.allowed_clients = 192.168.1.103  //监听的httpd服务器地址


      CentOS 7系统之 lamp (php-fpm)详解_wordpress_02


      [root@localhost ~]# mkdir /var/lib/php/session  //创建session目录

      [root@localhost ~]# chown apache.apache /var/lib/php/session

      [root@localhost ~]# ls -ld /var/lib/php/session

      drwxr-xr-x 2 apache apache 6 Jun  2 22:53 /var/lib/php/session


      [root@localhost ~]# systemctl start php-fpm.service

      CentOS 7系统之 lamp (php-fpm)详解_虚拟主机_03


   2) 创建httpd服务器连接php服务器的测试页


     [root@localhost ~]# mkdir /apps/vhosts/b.net -pv 

     [root@localhost ~]# mkdir /apps/vhosts/c.org -pv 


     [root@localhost ~]# vim /apps/vhosts/b.net/index.php  //虚拟主机www.b.net主机测试页

     CentOS 7系统之 lamp (php-fpm)详解_wordpress_04

     [root@localhost ~]# vim /apps/vhosts/c.org/index.php  //虚拟主机www.c.org主机测试页

     CentOS 7系统之 lamp (php-fpm)详解_wordpress_05


   3)windows物理机添加虚拟主机的解析

     

      CentOS 7系统之 lamp (php-fpm)详解_wordpress_06

    

   4)windows浏览器进行验证httpd服务器与php服务器的连接

    

      CentOS 7系统之 lamp (php-fpm)详解_wordpress_07


      CentOS 7系统之 lamp (php-fpm)详解_虚拟主机_08


    通过访问浏览器,证明httpd服务器与php服务器的连接是正常的。



 3、192.168.1.105主机安装配置mariadb

   

    1)安装mariadb服务器

 

    [root@localhost ~]# yum install mariadb mariadb-server -y 

    [root@localhost ~]# vim /etc/my.cnf

     skip_name_resolve=ON  //在[mysqld]下添加


    [root@localhost ~]# systemctl start mariadb.service

    [root@localhost ~]# mysql


   2)创建和授权wordpress和phpMyAdmin用户 


    MariaDB [(none)]> CREATE DATABASE wpdb; //创建wordpress数据

     MariaDB [(none)]> GRANT ALL ON wpdb.* TO wpuser@'192.168.%.%' IDENTIFIED BY 'wppass';  //授权wordpress用户

    MariaDB [(none)]> FLUSH PRIVILEGES;

 

    MariaDB [(none)]> CREATE DATABASE pma;  //创建phpMyAdmin数据库

    Query OK, 1 row affected (0.00 sec)

    MariaDB [(none)]> GRANT ALL ON pma.* TO pma@'192.168.%.%' IDENTIFIED BY 'pmapass';   

    Query OK, 0 rows affected (0.00 sec)

    MariaDB [(none)]> FLUSH PRIVILEGES;   

    Query OK, 0 rows affected (0.00 sec)


   3)php主机上创建php和mysql的测试页

    

     [root@localhost ~]# vim /apps/vhosts/b.net/index.php

      CentOS 7系统之 lamp (php-fpm)详解_php_09


    [root@localhost ~]# vim /apps/vhosts/c.org/index.php

      CentOS 7系统之 lamp (php-fpm)详解_wordpress_10


   4)windows浏览器进行验证php服务器与mysql服务器的连接


      CentOS 7系统之 lamp (php-fpm)详解_wordpress_11


      CentOS 7系统之 lamp (php-fpm)详解_php_12


    至此,httpd服务器、php服务器和mariadb服务器三者之间证明可以正常通信。




  4、php主机上安装phpMyAdmin


    1)下载解压phpMyAdmin


    [root@localhost vhosts]# cd  /apps/vhosts/c.org

    [root@localhost c.org]# ls

    phpMyAdmin-4.4.14.1-all-languages.zip  //下载phpMyAdmin压缩包https://www.phpmyadmin.net/downloads/

    [root@localhost c.org]# unzip phpMyAdmin-4.4.14.1-all-languages.zip

    [root@localhost c.org]# mv phpMyAdmin-4.4.14.1-all-languages pma

    [root@localhost c.org]# cd pma

    [root@localhost pma]# mv config.sample.inc.php config.inc.php

   

   2)配置phpMyAdmin 


    [root@localhost pma]# openssl rand -base64 15 //生成一段随机数

    Q6UQjkqqkH758gITfS45


    [root@localhost pma]# vim config.inc.php //编辑配置文件

    CentOS 7系统之 lamp (php-fpm)详解_php_13


    [root@localhost c.org]# scp -r pma root@192.168.1.103:/apps/vhosts/c.org/  

    // 此时需要把php主机的pma文件放到httpd主机的页面访问路径下


   3)httpd主机


    [root@localhost ~]# httpd -t  //测试语法

    Syntax OK

    [root@localhost ~]# systemctl restart httpd.service

    
   4)windows浏览器访问  www.c.org/pma


    CentOS 7系统之 lamp (php-fpm)详解_虚拟主机_14


    CentOS 7系统之 lamp (php-fpm)详解_虚拟主机_15


 5、下载安装配置wordpress



  1)下载解压wordpress


    [root@localhost conf.d]# cd /apps/vhosts/b.net/ 

     [root@localhost b.net]# ls  //下载wordpress压缩包(下载地址:https://wordpress.org/download/ 

     wordpress-4.3.1-zh_CN.zip

    [root@localhost b.net]# unzip wordpress-4.3.1-zh_CN.zip

    [root@localhost b.net]# cd wordpress/

    [root@localhost wordpress]# mv wp-config-sample.php wp-config.php

    [root@localhost wordpress]# vim wp-config.php

    

    CentOS 7系统之 lamp (php-fpm)详解_虚拟主机_16


    [root@localhost b.net]# scp -r wordpress root@192.168.1.103:/apps/vhosts/b.net/   //此时需要把php主机的wordpress文件放到httpd主机的页面访问路径下


  2)httpd主机


     [root@localhost ~]# httpd -t  //测试语法

    Syntax OK

    [root@localhost ~]# systemctl restart httpd.service



  3)windows浏览器访问 www.b.net/wordpress


    CentOS 7系统之 lamp (php-fpm)详解_php_17


    CentOS 7系统之 lamp (php-fpm)详解_虚拟主机_18

    


   


 6、php服务器安装xcache(配置好CentOS 7的epel源)


    1)未装xcache之前,压力测试  http://www.b.net/index.php

    

     [root@localhost ~]# ab -c 100 -n 1000 http://www.b.net/index.php


    CentOS 7系统之 lamp (php-fpm)详解_wordpress_19


    CentOS 7系统之 lamp (php-fpm)详解_php_20


    CentOS 7系统之 lamp (php-fpm)详解_wordpress_21


    

    2)安装xcache


    [root@localhost ~]# yum install php-xcache -y

    [root@localhost ~]# systemctl restart php-fpm.service


    CentOS 7系统之 lamp (php-fpm)详解_php_22



    3)进行压力测试


      [root@localhost ~]# ab -c 100 -n 1000 http://www.b.net/index.php


    CentOS 7系统之 lamp (php-fpm)详解_wordpress_23


    CentOS 7系统之 lamp (php-fpm)详解_wordpress_24



    CentOS 7系统之 lamp (php-fpm)详解_wordpress_25



    通过安装xcache,发现压力测试效果还是有提升的,我这里只是测试了几次,平时压力测试需要多次测试进行比较。