1. 云栖社区>
  2. PHP教程>
  3. 正文

centos7部署LAMP+xcache (php fpm模式)

作者:用户 来源:互联网 时间:2017-12-01 12:45:18

php部署lampcentos7模式fpmXCache

centos7部署LAMP+xcache (php fpm模式) - 摘要: 本文讲的是centos7部署LAMP+xcache (php fpm模式), centos7通过RPM包部署分离式LAMP+xcache (php-fpm)要求:rpm包部署LAMP,并且需要将LAMP环境进行分离式的部署(1)一个虚拟主机提供wordpress一个虚拟主机提供phpMyadmin(2)利用xcac

centos7通过RPM包部署分离式LAMP+xcache (php-fpm)

要求:
rpm包部署LAMP,并且需要将LAMP环境进行分离式的部署
(1)一个虚拟主机提供wordpress
一个虚拟主机提供phpMyadmin

(2)利用xcache来加速页面速度

环境:
此处用三台主机分别分离提供不同服务:
192.168.1.104------->提供httpd服务
192.168.1.110------->提供mariadb-server服务
192.168.1.113------->提供php-fpm php-mysql xcache服务

一、192.168.1.104服务器部署httpd服务:
1、安装httpd服务程序
[[email protected] ~]# yum -y install httpd[[email protected] ~]# vim /etc/httpd/conf/httpd.confServerNAme localhost:80 #修改下要不解析不出来,启动老慢了


2、建立虚拟主机
[[email protected] ~]# vim /etc/httpd/conf.d/vhosts1.confDirectoryIndex index.php<VirtualHost 192.168.1.104:80>ServerNAme wp.magedu.comDocumentRoot /data/vhosts/www1ProxyRequests offProxyPassMatch ^/(.*/.php)$ fcgi://192.168.1.113:9000/data/vhosts/www1/$1####表示包以.php开头的文件传给php-fpm来处理,此处地址是php服务器地址<Directory "/data/vhosts/www1">Options NoneAllowOverride NoneRequire all granted</Directory></VirtualHost>[[email protected] ~]# vim /etc/httpd/conf.d/vhosts2.confDirectoryIndex index.php<VirtualHost 192.168.1.104:80>ServerNAme pam.magedu.comDocumentRoot /data/vhosts/www2ProxyRequests offProxyPassMatch ^/(.*/.php)$ fcgi://192.168.1.113:9000/data/vhosts/www2/$1<Directory "/data/vhosts/www2">Options NoneAllowOverride NoneRequire all granted</Directory></VirtualHost>


3、建立网页及相关路径
[[email protected] ~]# mkdir -p /data/vhosts/www1[[email protected] ~]# mkdir -p /data/vhosts/www2[[email protected] ~]# echo "vhosts111" > /data/vhosts/www1/index.html [[email protected] ~]# echo "vhosts222" > /data/vhosts/www2/index.html


4、启动下服务我们测试下虚拟主机是否正常
[[email protected] www1]# curl http://wp.magedu.com vhosts111[[email protected] www1]# curl http://pam.magedu.com vhosts222


二、在192.168.1.113服务器上部署安装php-fpm

1、安装php-fpm php-mysql php-mbstring程序
[[email protected] ~]# rpm -q php  ###确保之前没有php程序,如果有看情况,不符合我们需要卸载package php is not installed[[email protected] ~]# yum -y install php-fpm php-mysql php-mbstring


2、编辑/etc/php-fpm.d/www.conf
[[email protected] ~]# vim /etc/php-fpm.d/listen = 192.168.1.113:9000 ###设置php服务器监听地址即监听本地能够与外部通信的地址listen.allowed_clients = 192.168.1.104 ###监听具有httpd服务的IP地址


3、建立以下文件并且启动php-fpm服务,查看下是否已经监听
[[email protected] ~]# mkdir /var/lib/php/session[[email protected] ~]# chown apache.apache /var/lib/php/session/[[email protected] ~]# ls -ld /var/lib/php/session/drwxr-xr-x 2 apache apache 6 Jul 18 20:37 /var/lib/php/session/[[email protected] ~]# systemctl start php-fpm.service [[email protected] ~]# ss -tnl State       Recv-Q Send-Q   Local Address:Port   LISTEN      0      128      192.168.1.113:9000 ####已经监听php地址 LISTEN      0      128  *:22     LISTEN      0      128  127.0.0.1:631    LISTEN      0      100  127.0.0.1:25 LISTEN      0      128  127.0.0.1:6010  LISTEN      0      128::1:631    LISTEN      0      100::1:25 LISTEN      0      128::1:6010


4、在php服务器上建立与http服务器上网页DocumentRoot路径,并且编写php测试也,看看是否能够与http连接
[[email protected] ~]# mkdir -p /data/vhosts/www1/ [[email protected] ~]# mkdir -p /data/vhosts/www2/[[email protected] ~]# vim /data/vhosts/www2/index.php ###虚拟主机2的php和httpd连接测试This is vhost2<?phpphpinfo();?>[[email protected] ~]# vim /data/vhosts/www1/index.php###虚拟主机1的php和httpd的连接测试This is vhost1<?phpphpinfo();?>


5、加载服务访问站点测试php和httpd连接是否正常

centos7部署LAMP+xcache (php fpm模式)

centos7部署LAMP+xcache (php fpm模式)
ok!此时证明了我们php服务器和http服务器已经连接成功了没有问题。

三、在192.168.1.110服务器上部署mariadb服务

1、安装mariadb服务
[[email protected] ~]# yum -y install mariadb-server[[email protected] ~]# systemctl start mariadb.service


2、创建等会需要用到的数据库和授权等相关操作
MariaDB [(none)]> CREATE DATABASE wpdb; ##创建WordPress所用数据库MariaDB [(none)]> GRANT ALL ON wpdb.* TO 'wpuser'@'192.168.%.%' IDENTIFIED BY 'wppass';###授权WordPress用户及操作操作MariaDB [(none)]> CREATE DATABASE pma;  ##授权phpmyadmin所用数据库MariaDB [(none)]> GRANT ALL ON pma.* TO 'pmauser'@'192.168.%.%' IDENTIFIED BY 'pmapass';       ###授权phpmyadmin的用户及操作权限       MariaDB [(none)]> grant all on *.* to 'pmauser'@'192.168.%.%' identified by 'pmapass';


3、在php服务器上建立php测试页,测试php是否可以正常连接数据

[[email protected] ~]# vim /data/vhosts/www1/index.php This is vhost1<?php$conn = mysql_connect('192.168.1.110','wpuser','wppass');    if ($conn)   echo "ok";    else   echo "NO";phpinfo();?>
[[email protected] ~]# vim /data/vhosts/www1/index.php This is vhost2<?php$conn = mysql_connect('192.168.1.110','pmauser','pmapass');if ($conn)echo "ok";elseecho "NO";phpinfo();?>~


4、测试

centos7部署LAMP+xcache (php fpm模式)

centos7部署LAMP+xcache (php fpm模式)
ok经过测试我们的mariadb数据可以同php连接了,到现在我们分离式的LAMP平台就基本构建完成了。。
centos7部署LAMP+xcache (php fpm模式)

四、下面我们就就来部署下WordPress和phpMyadmin
注意:此处我们是把程序放置php服务器当中去部署,不原来没分离情况是不一样的,千万习惯了搞错了啊。
部署WordPress:

1、解压包,配置连接用户和密码,数据可地址
[[email protected] ~]# unzip wordpress-4.3.1-zh_CN.zip[[email protected] ~]# mv wordpress /data/vhosts/www1/[[email protected] ~]# cd /data/vhosts/www1/wordpress/[[email protected] wordpress]# mv wp-config-sample.php wp-config.php[[email protected] wordpress]# vim wp-config.php define('DB_NAME', 'wpdb');/** MySQL数据库用户名 */define('DB_USER', 'wpuser');/** MySQL数据库密码 */define('DB_PASSWORD', 'wppass');/** MySQL主机 */define('DB_HOST', '192.168.1.110');


2、此时我们需要把WordPress这个目录个传到http服务器主页访问的路径下
[[email protected] www1]# pwd/data/vhosts/www1[[email protected] www1]# lsindex.php  wordpress[[email protected] www1]# scp -r wordpress/ [email protected]:/data/vhosts/www1/    ###目录传到http服务器上


部署phpMyadmin:
1、解压包配置
[[email protected] ~]# unzip phpMyAdmin-4.4.14.1-all-languages.zip[[email protected] ~]# mv phpMyAdmin-4.4.14.1-all-languages /data/vhosts/www2/[[email protected] www2]# mv phpMyAdmin-4.4.14.1-all-languages/ phpmyadmin


2、编辑配置文件
[[email protected] libraries]# pwd/data/vhosts/www2/phpmyadmin/libraries[[email protected] libraries]# vim config.default.php $cfg['blowfish_secret'] = 'V40VdxxM0rPrx8k2KYE';$cfg['Servers'][$i]['host'] = '192.168.1.110'; ###数据库服务器地址$cfg['Servers'][$i]['user'] = 'pmauser';$cfg['Servers'][$i]['password'] = 'pmapass';


3、将配置好了的phpmyadmin目录传一份给httpd服务器虚拟主机对应的访问路径下
[[email protected] www2]# scp -r phpmyadmin/ [email protected]:/data/vhosts/www2/
测试:


centos7部署LAMP+xcache (php fpm模式)

centos7部署LAMP+xcache (php fpm模式)

ok了下面我们对页面进行一次压力测试看看速度:
[[email protected] ~]# ab -n 10000 -c 1000 http://wp.magedu.com/wordpress This is ApacheBench, Version 2.3 <$Revision: 655654 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking wp.magedu.com (be patient)Completed 1000 requestsCompleted 2000 requestsCompleted 3000 requestsCompleted 4000 requestsCompleted 5000 requestsCompleted 6000 requestsCompleted 7000 requestsCompleted 8000 requestsCompleted 9000 requestsCompleted 10000 requestsFinished 10000 requestsServer Software:Apache/2.4.6Server Hostname:wp.magedu.comServer Port:    80Document Path:  /wordpressDocument Length:239 bytesConcurrency Level:      1000Time taken for tests:   3.081 secondsComplete requests:      10000Failed requests:0Write errors:   0Non-2xx responses:      10002Total transferred:      4690938 bytesHTML transferred:       2390478 bytesRequests per second:    3245.20 [#/sec] (mean)Time per request:       308.147 [ms] (mean)Time per request:       0.308 [ms] (mean, across all concurrent requests)Transfer rate:  1486.63 [Kbytes/sec] received
从这段测试可以看出,这没加速度比我们之前的基于module+xcache的都要快。。。。

五、在php服务器安徽192.168.1.113上安装xcache进行缓存加速
1、安装php-xache
[[email protected] ~]# yum -y install php-xcache [[email protected] ~]# systemctl restart php-fpm.service


2、编辑配置文件,我吧缓存大小调整大写看看效果
[[email protected] ~]# vim /etc/php.d/xcache.inixcache.size  =       300M


3、压力测试:

[[email protected] ~]# ab -n 10000 -c 1000 http://wp.magedu.com/wordpress This is ApacheBench, Version 2.3 <$Revision: 655654 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking wp.magedu.com (be patient)Completed 1000 requestsCompleted 2000 requestsCompleted 3000 requestsCompleted 4000 requestsCompleted 5000 requestsCompleted 6000 requestsCompleted 7000 requestsCompleted 8000 requestsCompleted 9000 requestsCompleted 10000 requestsFinished 10000 requestsServer Software:Apache/2.4.6Server Hostname:wp.magedu.comServer Port:    80Document Path:  /wordpressDocument Length:239 bytesConcurrency Level:      1000Time taken for tests:   3.076 secondsComplete requests:      10000Failed requests:0Write errors:   0Non-2xx responses:      10012Total transferred:      4695628 bytesHTML transferred:       2392868 bytesRequests per second:    3250.70 [#/sec] (mean)Time per request:       307.626 [ms] (mean)Time per request:       0.308 [ms] (mean, across all concurrent requests)Transfer rate:  1490.63 [Kbytes/sec] receivedConnection Times (ms)      min  mean[+/-sd] median   maxConnect:0   46 208.7      2    3011Processing:     0   69 191.8     31    1575Waiting:0   68 191.7     31    1574Total: 21  115 337.5     34    3040

以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索php , 部署 , lamp , centos7 , 模式 , fpm XCache ,以便于您获取更多的相关知识。