1、实验环境:
Linux服务器操作系统版本:CentOS 7.2
http               IP: 172.16.251.138

httpd-2.4.6.tar      apr-util-1.5.2.tar  

wordpress-4.3.1-zh_CN    apr-1.5.0.tar

phpMyAdmin-4.4.14.1-all-languages
php-fpm            IP:172.16.251.222

xcache-3.1.0.tar        php-5.4.26.tar 

mariadb            IP:172.16.251.188

mariadb-5.5.46-linux-x86_64.tar (二进制包)

客户端             IP:172.16.251.164


2、实验准备:

[root@station138 ~]# iptables –F                   //关闭防火墙

[root@station138 ~]#setenforce0                  //关闭SeLinux

[root@station138 ~]# rpm –e httpd mod_ssl mod_perlsystem-config-httpd php php-cli php-ldap php-common php-mairadb  mariadb-server          //卸载相关软件,防止冲突


3、安装开发包组,安装支持软件解决依赖关系:

[root@station138 ~]#yum -y groupinstall "Development Tools" "Server Platform Development"

[root@station138 ~]#tar xf apr-1.5.0.tar.bz2 

[root@station138 apr-1.5.0]# ./configure --prefix=/usr/local/apr

[root@station138 apr-1.5.0]# make && make install

[root@station138 ~]#tar xf apr-util-1.5.2.tar.bz2

[root@station138 apr-util-1.5.2]#./configure --prefix=/usr/local/apr-util \

> --with-apr=/usr/local/apr                                 

[root@station138 apr-util-1.5.2]#make && make install

[root@station138 ~]# yum -y install pcre-devel  openssl-devel  libevent-devel


4、源代码安装Apache:

a.编译httpd

[root@station138 ~]# tar xf httpd-2.4.6.tar.bz2 
[root@station138 ~]# cd httpd-2.4.6/
[root@station138 httpd-2.4.6]# ./configure \
> --prefix=/usr/local/apache          //安装路径
> --sysconfdir=/etc/httpd24          //配置文件路径
> --enable-so   //支持动态装卸载DSO机制,DSO是动态共享对象,可实现模块动态生效
> --enable-ssl  //支持SSL/TLS 可实现https功能,需要安装openssl-devel开发工具
> --enable-cgi  //支持CGI脚本 默认对非线程的MPM(多路处理)模块开启

> --enable-rewrite          //支持URL重写

> --enable-defalte          //支持压缩功能
> --enable-modules=most     //支持动态启用的模块 {all|most}
> --enable-mpms-shared=all  //支持动态加载的MPM模块 {most|all}
> --with-mpm=prefork        //设置默认启用的mpm模式 {prefork|worker|event}
> --with-pcre               //使用指定的pcre库,需要安装pcre-devel工具
> --with-zlib               //使用指定的zlib库
> --with-apr=/usr/local/apr  //指定apr安装路径
> --with-apr-util=/usr/local/apr-util  //指定apr-util安装路径

[root@station138 httpd-2.4.6]# make && make install

b.添加PATH环境变量:

[root@station138 ~]# vim /etc/profile.d/httpd24.sh 

export PATH=/usr/local/apache/bin:$PATH

[root@station138 ~]# source /etc/profile.d/httpd24.sh

c.启动服务:

[root@station138 ~]# ln -sv /usr/local/apache/include/ /usr/include/httpd24

[root@station138 ~]# apachectl start 

[root@station138 ~]# ss -tnl 

LISTEN     0      128                        :::80                                     :::*


5、二进制安装mariadb:

a.建立mysql用户和组

[root@station188 ~]# useradd -r -M mysql

b.建立数据存放的目录

[root@station188 ~]# mkdir -p /data/mydata

[root@station188 ~]# chown -R mysql:mysql /data/mydata/

c.解压mariadb安装包

[root@station188 ~]# tar xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local

[root@station188 ~]# ln -sv /usr/local/mariadb-5.5.46-linux-x86_64/ mysql 

[root@station188 ~]# chown -R root.mysql /usr/local/mysql/*

c.使用scripts脚本文件mysql_install_db文件来安装数据库

[root@station188 mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mydata

d.提供配置文件

[root@station188 mysql]# cp support-files/my-large.cnf /etc/my.cnf

[root@station188 mysql]# vim /etc/my.cnf

datadir=/data/mydata         //指明mysql的数据存放路径

innodb_file_per_table = ON   //成为独立表空间

skip_name_resolve = ON       //跳过名称解析

e.提供mysql服务启动脚本

[root@station188 support-files]# cp mysql.server /etc/rc.d/init.d/mysqld  
[root@station188 support-files]# chkconfig --add mysqld

f.添加环境变量

[root@station188 ~]# vim /etc/profile.d/mysql.sh 
export PATH=/usr/local/mysql/bin:$PATH

[root@station188 ~]# source /etc/profile.d/mysql.sh

g.导出头文件

[root@station188 ~]# ln -s /usr/local/include/ /usr/include/mysql

h.导出库文件:

[root@station188 ~]# vim /etc/ld.so.conf.d/mysql.conf

i.启动服务

[root@station188 ~]# systemctl start mysqld 

[root@station188 ~]# ss -tnl 

LISTEN     0      50           *:3306     *:*   


6、源代码安装PHP

a.安装开发包组及依赖关系的包

[root@station222 ~]# yum -y groupinstall "Development Tools" "Server Platform Development" 

[root@station222 ~]# yum -y install bzip2-devel libmcrypt-devel libxml2-devel openssl-devel

b.编译php

[root@station222 ~]# tar xf php-5.4.26.tar.bz2 
[root@station222 ~]# cd php-5.4.26/

[root@station222 php-5.4.26]# ./configure\

 --prefix=/usr/local/php --with-openssl --with-mysql=mysqlnd

 --with-pdo-mysql=mysqlnd --with-mysql=mysqlnd --enable-mbstring 
--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib
--with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt

--with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2

[root@station222 php-5.4.26]# make && make install

c.php提供配置文件

[root@station222 php-5.4.26]# cp php.ini-production /etc/php.ini

d.提供php-fpm脚本

[root@station222 php-5.4.26]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@station222 php-5.4.26]# chmod +x /etc/rc.d/init.d/php-fpm 

[root@station222 php-5.4.26]# chkconfig --add php-fpm

e.提供php-fpm配置文件

[root@station222 php-5.4.26]# cd /usr/local/php

[root@station222 php-5.4.26]# cp etc/php-fpm.conf.default etc/php-fpm.conf

f.启动服务

[root@station222 php-5.4.26]# systemctl start php-fpm
[root@station222 php-5.4.26]# ss -tnl 
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              

LISTEN      0      128       127.0.0.1:9000                          *:*


7、httpd配置

a.支持fastFCGI的模块

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

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

Include /etc/httpd24/extra/httpd-vhosts.conf

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

b.配置虚拟主机

[root@station138 ~]# vim /etc/httpd24/extra/httpd-vhosts.conf
Directory Index index.php
    DocumentRoot "/data/vhost1/www1"
    ServerName  www1.b.com

    ProxyRequests off

        Directoryindex index.php

    ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.251.222:9000/data/vhost1/www1/$1
   
        Options None
        AllowOverride None
        Require all granted
   
 
    DocumentRoot "/data/vhost2/www2"
    ServerName www2.b.com

    ProxyRequests off

          Directoryindex index.php

    ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.251.222:9000/data/vhost2/www2/$1
     
         Options None
         AllowOverride None
         Require all granted
     

c.测试重启服务

[root@station138 ~]# mkdir -p /data/vhost1/www1

[root@station138 ~]# mkdir -p /data/vhost2/www2

[root@station138 ~]# apachectl -t

[root@station138 ~]# apachectl restart 


8、配置php-fpm

[root@station222 ~]# vim /usr/local/php/etc/php-fpm.conf

pid = run/php-fpm.pid  
listen.allowed_clients = 172.16.251.138

listen = 172.16.251.222:9000 

[root@station222 ~]# systemctl restart php-fpm.service 
[root@station222 ~]# ss -tnl 
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              

LISTEN      0      128    172.16.251.222:9000                          *:*

测试php和http之间是否正常

[root@station222 ~]# mkdir -p /data/vhost1/www1
[root@station222 ~]# mkdir -p /data/vhost2/www2

[root@station222 ~]# vim /data/vhost1/www1/index.php
phpinfo();
?>

客户端测试httpd是否连接php-fpm:

http://www1.b.com


9、配置mariadb

a.创建授权用户

[root@station188 ~]#mysql -uroot -p

MariaDB [(none)]> create database wpdb;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on wpdb.* to  'wpuser' @ '172.16.%.%' identified by 'wp123';
Query OK, 0 rows affected (0.03 sec)
MariaDB [(none)]> create database pma;  
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> grant all on pma.* to  'pmauser' @ '172.16.%.%' identified by 'pma123';
Query OK, 0 rows affected (0.00 sec)

b.Php和mysql的链接测试

[root@station222 ~]# vim /data/vhost1/www1/index.php 

$conn = mysql_connect('172.16.251.188','wpuser','wp123');
        if ($conn)
                echo "ok";
        else
                echo "no";
?>

客户端测试php是否连接mysql:

http://www1.b.com


10、部署WordPress:

[root@station222 ~]# unzip wordpress-4.3.1-zh_CN.zip 
[root@station222 ~]# mv wordpress /data/vhost1/www1/
[root@station222 ~]# cd /data/vhost1/www1/wordpress/
[root@station222 wordpress]# mv wp-config-sample.php wp-config.php 
[root@station222 wordpress]# vim wp-config.php 
/** WordPress数据库的名称 */
define('DB_NAME', 'wpdb');
/** MySQL数据库用户名 */
define('DB_USER', 'wpuser');
/** MySQL数据库密码 */
define('DB_PASSWORD', 'wp123');
/** MySQL主机 */

define('DB_HOST', '172.16.251.188');

[root@station222 www1]#scp -r wordpress/ [email protected]:/data/vhost1/www1/


11、部署phpmyadmin:

[root@station222 ~]# unzip phpMyAdmin-4.4.14.1-all-languages.zip
[root@station222 ~]# mv phpMyAdmin-4.4.14.1-all-languages /data/vhost2/www2/
[root@station222 www2]# ln -sv phpMyAdmin-4.4.14.1-all-languages/ phpmyadmin
[root@station222 www2]# vim phpmyadmin/libraries/config.default.php
$cfg['blowfish_secret'] = 'tSQRO02T+grA6rvJHCXr';
$cfg['Servers'][$i]['host'] = '172.16.251.188'; 
$cfg['Servers'][$i]['user'] = 'pmauser';

$cfg['Servers'][$i]['password'] = 'pma123';

[root@station222 www2]# scp -r phpmyadmin/ [email protected]:/data/vhost2/www2/



12.压力测试

a.测试wordpress

[root@station222 ~]# ab -c 100 -n 1000 http://www1.b.com/wordpress

Concurrency Level:      100

Time taken for tests:   3.347 seconds

Completerequests:      1000                                                

Failed requests:        0

Write errors:           0

Total transferred:      174000 bytes

HTML transferred:       2000 bytes

Requests per second:    298.75 [#/sec] (mean)

Time per request:       334.730 [ms] (mean)

Time per request:       3.347 [ms] (mean, across all concurrentrequests)

Transfer rate:          50.76 [Kbytes/sec] received

b.编译安装xcache缓存加速

[root@station222 ~]# tar xf xcache-3.2.0.tar.bz2 
[root@station222 ~]# cd xcache-3.2.0/
[root@station222 xcache-3.2.0]# /usr/local/php/bin/phpize

[root@station222 xcache-3.2.0]# ./configure \

> --enable-xcache --with-php-config=/usr/local/php/bin/php-config

[root@station222 xcache-3.2.0]# make && make install
[root@station222 ~]# cp /xcache-3.2.0/xcache.ini  /etc/php.d/
[root@station222 ~]# vim /etc/php.d/xcache.ini 
添加:
[xcache-common]
extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache.so
修改下缓存大小:
xcache.size  =               200M

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

c.安装xcache后再测试

[root@station222 ~]# ab -c 100 -n 1000 http://www1.b.com/wordpress

Concurrency Level:      100
Time taken for tests:   2.128 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Non-2xx responses:      1000
Total transferred:      4670000 bytes
HTML transferred:       2390000 bytes
Requests per second:    4700.07 [#/sec] (mean)
Time per request:       212.763 [ms] (mean)
Time per request:       0.213 [ms] (mean, across all concurrent requests)
Transfer rate:          2143.49 [Kbytes/sec] received