CentOS 7系统之 lamp (php-fpm)详解
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 7系统之 lamp (php-fpm)详解相关的知识,希望对你有一定的参考价值。
安装要求:
(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 |
1、192.168.1.103 安装配置httpd
1)安装配置httpd
[[email protected] ~]# yum install httpd -y
[[email protected] ~]# vim /etc/httpd/conf/httpd.conf
#DocumentRoot "/var/www/html" //注释web默认访问路径
[[email protected] ~]# mkdir /apps/vhosts/b.net -pv //创建虚拟主机wordpress访问页面
[[email protected] ~]# mkdir /apps/vhosts/c.org -pv //创建虚拟主机phpMyAdmin访问页面
2)基于虚拟主机配置
[[email protected] ~]# vim /etc/httpd/conf.d/vhosts.conf //创建并配置虚拟主机的配置文件
2、192.168.1.104安装配置 php-fpm ,php-mysql
1)安装配置php-fpm
[[email protected] ~]# rpm -q php //确保没有装载php包
package php is not installed
[[email protected] ~]# yum install php-fpm php-mysql php-mbstring -y
[[email protected] ~]# vim /etc/php-fpm.d/www.conf
listen = 192.168.1.104:9000 //修改php服务器监听地址
listen.allowed_clients = 192.168.1.103 //监听的httpd服务器地址
[[email protected] ~]# mkdir /var/lib/php/session //创建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 Jun 2 22:53 /var/lib/php/session
[[email protected] ~]# systemctl start php-fpm.service
2) 创建httpd服务器连接php服务器的测试页
[[email protected] ~]# mkdir /apps/vhosts/b.net -pv
[[email protected] ~]# mkdir /apps/vhosts/c.org -pv
[[email protected] ~]# vim /apps/vhosts/b.net/index.php //虚拟主机www.b.net主机测试页
[[email protected] ~]# vim /apps/vhosts/c.org/index.php //虚拟主机www.c.org主机测试页
3)windows物理机添加虚拟主机的解析
4)windows浏览器进行验证httpd服务器与php服务器的连接
通过访问浏览器,证明httpd服务器与php服务器的连接是正常的。
3、192.168.1.105主机安装配置mariadb
1)安装mariadb服务器
[[email protected] ~]# yum install mariadb mariadb-server -y
[[email protected] ~]# vim /etc/my.cnf
skip_name_resolve=ON //在[mysqld]下添加
[[email protected] ~]# systemctl start mariadb.service
[[email protected] ~]# mysql
2)创建和授权wordpress和phpMyAdmin用户
MariaDB [(none)]> CREATE DATABASE wpdb; //创建wordpress数据
MariaDB [(none)]> GRANT ALL ON wpdb.* TO [email protected]‘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 [email protected]‘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的测试页
[[email protected] ~]# vim /apps/vhosts/b.net/index.php
[[email protected] ~]# vim /apps/vhosts/c.org/index.php
4)windows浏览器进行验证php服务器与mysql服务器的连接
至此,httpd服务器、php服务器和mariadb服务器三者之间证明可以正常通信。
4、php主机上安装phpMyAdmin
1)下载解压phpMyAdmin
[[email protected] vhosts]# cd /apps/vhosts/c.org
[[email protected] c.org]# ls
phpMyAdmin-4.4.14.1-all-languages.zip //下载phpMyAdmin压缩包(https://www.phpmyadmin.net/downloads/)
[[email protected] c.org]# unzip phpMyAdmin-4.4.14.1-all-languages.zip
[[email protected] c.org]# mv phpMyAdmin-4.4.14.1-all-languages pma
[[email protected] c.org]# cd pma
[[email protected] pma]# mv config.sample.inc.php config.inc.php
2)配置phpMyAdmin
[[email protected] pma]# openssl rand -base64 15 //生成一段随机数
Q6UQjkqqkH758gITfS45
[[email protected] pma]# vim config.inc.php //编辑配置文件
[[email protected] c.org]# scp -r pma [email protected]:/apps/vhosts/c.org/
// 此时需要把php主机的pma文件放到httpd主机的页面访问路径下
3)httpd主机
[[email protected] ~]# httpd -t //测试语法
Syntax OK
[[email protected] ~]# systemctl restart httpd.service
4)windows浏览器访问 www.c.org/pma
5、下载安装配置wordpress
1)下载解压wordpress
[[email protected] conf.d]# cd /apps/vhosts/b.net/
[[email protected] b.net]# ls //下载wordpress压缩包(下载地址:https://wordpress.org/download/ )
wordpress-4.3.1-zh_CN.zip
[[email protected] b.net]# unzip wordpress-4.3.1-zh_CN.zip
[[email protected] b.net]# cd wordpress/
[[email protected] wordpress]# mv wp-config-sample.php wp-config.php
[[email protected] wordpress]# vim wp-config.php
[[email protected] b.net]# scp -r wordpress [email protected]:/apps/vhosts/b.net/ //此时需要把php主机的wordpress文件放到httpd主机的页面访问路径下
2)httpd主机
[[email protected] ~]# httpd -t //测试语法
Syntax OK
[[email protected] ~]# systemctl restart httpd.service
3)windows浏览器访问 www.b.net/wordpress
6、php服务器安装xcache(配置好CentOS 7的epel源)
1)未装xcache之前,压力测试 http://www.b.net/index.php
[[email protected] ~]# ab -c 100 -n 1000 http://www.b.net/index.php
2)安装xcache
[[email protected] ~]# yum install php-xcache -y
[[email protected] ~]# systemctl restart php-fpm.service
3)进行压力测试
[[email protected] ~]# ab -c 100 -n 1000 http://www.b.net/index.php
通过安装xcache,发现压力测试效果还是有提升的,我这里只是测试了几次,平时压力测试需要多次测试进行比较。
以上是关于CentOS 7系统之 lamp (php-fpm)详解的主要内容,如果未能解决你的问题,请参考以下文章
Centos7-yum部署配置LAMP-之LAMP及php-fpm实现反代动态资源
CentOS 7 yum安装lamp,三者位于不同服务器,并为之安装WordPress及phpmyadmin