要求:httpd的动态和静态资源分为两台主机提供,mysql也用单独一台主机httpd服务提供虚拟主机,一个虚拟主机用于提供phpMyAdmin;另一个虚拟主机用于提供wordpress安装使用xcache为php服务提速。
方案:1台主机作为httpd服务器,1台主机做php服务器,使用php-fpm模式,1台主机作为mysql数据库服务器。准备工作:三台主机,配置好yum源。
![在CentOS 7 上搭建LAMP插图 在CentOS 7 上搭建LAMP插图](http://www.tiejiang.org/wp-content/uploads/2016/04/20160424113847119.png)
第一步:配置httpd服务器yum安装httpd包~]# yum install httpd
![在CentOS 7 上搭建LAMP插图1 在CentOS 7 上搭建LAMP插图1](http://www.tiejiang.org/wp-content/uploads/2016/04/20160424113847215.png)
启动服务
![在CentOS 7 上搭建LAMP插图2 在CentOS 7 上搭建LAMP插图2](http://www.tiejiang.org/wp-content/uploads/2016/04/20160424113847319.png)
测试是否能提供服务页面
![在CentOS 7 上搭建LAMP插图3 在CentOS 7 上搭建LAMP插图3](http://www.tiejiang.org/wp-content/uploads/2016/04/20160424113848415.png)
httpd服务工作正常2. 配置虚拟主机和定义动态页面转发到php服务器。注释掉主服务页面路径~]# vim /etc/httpd/conf/httpd.conf
![在CentOS 7 上搭建LAMP插图4 在CentOS 7 上搭建LAMP插图4](http://www.tiejiang.org/wp-content/uploads/2016/04/20160424113848515.png)
添加一个配置文件,用于定义虚拟主机和定义转发~]# touch /etc/httpd/conf.d/virtualhost.conf~]# vim /etc/httpd/conf.d/virtualhost.conf。
![在CentOS 7 上搭建LAMP插图5 在CentOS 7 上搭建LAMP插图5](http://www.tiejiang.org/wp-content/uploads/2016/04/20160424113848616.png)
3. 测试虚拟主机~]# touch /var/virtualhost/a/check.html~]# vim /var/virtualhost/a/check.html
![在CentOS 7 上搭建LAMP插图6 在CentOS 7 上搭建LAMP插图6](http://www.tiejiang.org/wp-content/uploads/2016/04/20160424113848713.png)
~]# touch /var/virtualhost/b/check.html~]# vim /var/virtualhost/b/check.html
![在CentOS 7 上搭建LAMP插图7 在CentOS 7 上搭建LAMP插图7](http://www.tiejiang.org/wp-content/uploads/2016/04/20160424113849816.png)
在访问测试的主机中定义将www.a.com和www.b.com解析为httpd服务器的ip地址
![在CentOS 7 上搭建LAMP插图8 在CentOS 7 上搭建LAMP插图8](http://www.tiejiang.org/wp-content/uploads/2016/04/20160424113849911.png)
![在CentOS 7 上搭建LAMP插图9 在CentOS 7 上搭建LAMP插图9](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138491014.png)
注:httpd-2.4:rpm包安装默认编译支持了fcgi模块;可以使用httpd -M查看已经加载的模块。
![在CentOS 7 上搭建LAMP插图10 在CentOS 7 上搭建LAMP插图10](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138491113.png)
4.使用systemctl enable httpd.service将服务设置为开机启动第二步:配置php服务器yum安装php-fpm包~]# yum install php-fpm查看状态
![在CentOS 7 上搭建LAMP插图11 在CentOS 7 上搭建LAMP插图11](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138491210.png)
2. 修改配置文件
![在CentOS 7 上搭建LAMP插图12 在CentOS 7 上搭建LAMP插图12](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138501316.png)
![在CentOS 7 上搭建LAMP插图13 在CentOS 7 上搭建LAMP插图13](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138501415.png)
![在CentOS 7 上搭建LAMP插图14 在CentOS 7 上搭建LAMP插图14](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138501517.png)
![在CentOS 7 上搭建LAMP插图15 在CentOS 7 上搭建LAMP插图15](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138501616.png)
~]# mkdir /var/lib/php/session~]# chown apache:apache /var/lib/php/session3. 启动服务,查看状态
![在CentOS 7 上搭建LAMP插图16 在CentOS 7 上搭建LAMP插图16](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138501710.png)
4. 在php服务器的资源路径下添加测试页面并测试~]# vim /var/phppage/a/check.php
![在CentOS 7 上搭建LAMP插图17 在CentOS 7 上搭建LAMP插图17](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138511814.png)
~]# vim /var/phppage/b/check.php
![在CentOS 7 上搭建LAMP插图18 在CentOS 7 上搭建LAMP插图18](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138511915.png)
访问
![在CentOS 7 上搭建LAMP插图19 在CentOS 7 上搭建LAMP插图19](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138512016.png)
![在CentOS 7 上搭建LAMP插图20 在CentOS 7 上搭建LAMP插图20](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138512116.png)
5.安装php-mysql包(php和mysql之间的通信协议)~]# yum install php-mysql然后重载一下服务~]# systemctl reload php-fpm.service
6.使用systemctl enable php-fpm.service将服务设置为开机启动第三部:配置mysql服务器yum安装mariadb包~]# yum install mariadb-server
![在CentOS 7 上搭建LAMP插图21 在CentOS 7 上搭建LAMP插图21](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138522214.png)
2.启动服务
![在CentOS 7 上搭建LAMP插图22 在CentOS 7 上搭建LAMP插图22](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138522318.png)
3.测试创建一个测试用户和数据库
![在CentOS 7 上搭建LAMP插图23 在CentOS 7 上搭建LAMP插图23](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138522410.png)
在php服务器上放置网页资源的路径下添加测试页面
![在CentOS 7 上搭建LAMP插图24 在CentOS 7 上搭建LAMP插图24](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138522510.png)
![在CentOS 7 上搭建LAMP插图25 在CentOS 7 上搭建LAMP插图25](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138522612.png)
![在CentOS 7 上搭建LAMP插图26 在CentOS 7 上搭建LAMP插图26](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138532711.png)
访问测试
![在CentOS 7 上搭建LAMP插图27 在CentOS 7 上搭建LAMP插图27](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138532816.png)
![在CentOS 7 上搭建LAMP插图28 在CentOS 7 上搭建LAMP插图28](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138532913.png)
4.使用systemctl enable mariadb.service将服务设置为开机启动LAMP搭建完成,可以正常提供服务第四步:用www.a.com这个虚拟主机提供phpMyAdmin,用www.b.com这个虚拟主机提供wordpress。
1.准备phpMyAdmin,wordpress的源码包
![在CentOS 7 上搭建LAMP插图29 在CentOS 7 上搭建LAMP插图29](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138533011.png)
2.解压到放置页面资源的路径下~]# unzip phpMyAdmin-4.4.14.1-all-languages.zip -d /var/phppage/a3.编辑其配置文件
![在CentOS 7 上搭建LAMP插图30 在CentOS 7 上搭建LAMP插图30](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138533111.png)
![在CentOS 7 上搭建LAMP插图31 在CentOS 7 上搭建LAMP插图31](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138533218.png)
4.访问
![在CentOS 7 上搭建LAMP插图32 在CentOS 7 上搭建LAMP插图32](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138533316.png)
已经可以访问了,但是发现页面有些地方无法显示这是因为此页面是由动态资源和静态资源组成的,而httpd服务器只是把动态资源请求转发到php服务器了,静态资源是httpd提供,它现在资源路径下并没有此资源,所以此页面显示不全。
原理可见下图
![在CentOS 7 上搭建LAMP插图33 在CentOS 7 上搭建LAMP插图33](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138543415.jpg)
解决方案:在httpd服务器上的资源放置路径下同样放置一份phpMyAdmin源码文件,这样页面就可以显示完全了现在我们要访问phpMyAdmin这个页面时,需要在给出域名的同时还要指定url这样太麻烦。
有两个方案可以解决第一个方案:修改虚拟主机的配置,修改DocumentRoot 路径 同时修改转发后的路径DocumentRoot /var/virtualhost/a/phpMyAdmin-4.4.14.1-all-languages。
ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.0.132:9000/var/phppage/a/phpMyAdmin-4.4.14.1-all-languages/$1
![在CentOS 7 上搭建LAMP插图34 在CentOS 7 上搭建LAMP插图34](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138543516.png)
然后使用httpd -t测试配置文件语法,再重载一下配置文件,就可以了
![在CentOS 7 上搭建LAMP插图35 在CentOS 7 上搭建LAMP插图35](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138543617.png)
第二个方案:将所有phpMyAdmin源码文件直接放在DocumentRoot 路径下。php服务器则直接放在指定转发后的路径下。
![在CentOS 7 上搭建LAMP插图36 在CentOS 7 上搭建LAMP插图36](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138543715.png)
![在CentOS 7 上搭建LAMP插图37 在CentOS 7 上搭建LAMP插图37](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138543812.png)
布置wordpress~]# unzip wordpress-4.3.1-zh_CN.zip -d /var/phppage/b]# ]# cp wp-config-sample.php wp-config.php
]# vim wp-config.php
![在CentOS 7 上搭建LAMP插图38 在CentOS 7 上搭建LAMP插图38](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138543913.png)
注意:这样wp用来登陆和使用的数据库用户需提前创建。后续过程类似配置phpMyAdmin,就不重复了。第五步:安装xcache,提高处理php请求速度1.安装前先做一下压力测试
![在CentOS 7 上搭建LAMP插图39 在CentOS 7 上搭建LAMP插图39](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138544011.png)
![在CentOS 7 上搭建LAMP插图40 在CentOS 7 上搭建LAMP插图40](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138554118.png)
这次我们使用编译安装xcache准备工作:下载一个xcache源码包,安装Development Tools和Server Platform Development包组安装php-devel包2.开始编译。
![在CentOS 7 上搭建LAMP插图41 在CentOS 7 上搭建LAMP插图41](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138554215.png)
如果这一步没问题,执行make,然后执行make instal。安装完成后,添加配置文件,然后让服务重载。
![在CentOS 7 上搭建LAMP插图42 在CentOS 7 上搭建LAMP插图42](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138554320.png)
3.再做一次压力测试
![在CentOS 7 上搭建LAMP插图43 在CentOS 7 上搭建LAMP插图43](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138554417.png)
![在CentOS 7 上搭建LAMP插图44 在CentOS 7 上搭建LAMP插图44](http://www.tiejiang.org/wp-content/uploads/2016/04/201604241138554514.png)
对比两次压力测试可以看出,装了xcache以后,php请求处理速度提高3倍左右。