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

前端之家收集整理的这篇文章主要介绍了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




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 //创建并配置虚拟主机的配置文件


wKiom1dQ6nGwkx79AABP1mg6Mus378.png




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服务器地址


wKiom1dQ46XDHDJJAABChnxs72U085.png


[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

wKioL1dQ5oWgyyf4AAATT5074kw622.png


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主机测试页

wKiom1dQ50OyR4IyAAANmNVPsWg896.png

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

wKioL1dQ6FjBzg8WAAANZ-Zz8OA912.png


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


wKiom1dQ6JXw5rJqAAA4UkHyfe4619.png

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

wKiom1dQ6tOjKbmNAAChDUNoQUM925.png

wKioL1dQ6-mTsWzmAACamEoTOAw969.png

通过访问浏览器,证明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)创建和授权wordpressPHPMyAdmin用户


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';

MariaDB [(none)]> FLUSH PRIVILEGES;


3)PHP主机上创建PHPMysqL的测试页


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

wKiom1dQ7nqjKGoGAAAcWOyfbzg997.png


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

wKiom1dQ8LjgGI_oAAAaybicQhk410.png


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


wKioL1dQ8kfQMo9bAACRMEo7WTw644.png


wKiom1dQ8VayMUM9AACY7RUFDkI216.png


至此,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 //编辑配置文件

wKioL1dQ9rOgx-v5AABYBWnhANw001.png


[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


wKiom1dRBVmiNWrLAACccGKT26M190.png

wKiom1dRBWvTwI0XAAGBHK52Sxg113.png


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


wKiom1dQRiCzNPdQAAA7aYjQVQY056.png


[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


wKiom1dRAwHjjLXwAACEMg-t4Ac443.png


wKioL1dRBBnRNYcCAADB2C8aEqs411.png



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


wKiom1dRCniCi8loAAAwIu0FOao129.png


wKiom1dRCobRWeJzAAAw85MCrEw268.png


wKiom1dRCpLAvkayAAA70maDFD8503.png


2)安装xcache


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

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


wKioL1dRD6qyUWY3AAAjBu9s5gA378.png



3)进行压力测试


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


wKioL1dREa6hsIWPAAA8aClWM0k407.png


wKiom1dREL2zHrqbAAA73l9u2o0167.png



wKioL1dREcuguE9lAAA6-y44dS4568.png



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

原文链接:https://www.f2er.com/centos/382137.html

猜你在找的CentOS相关文章