PHP加速和部署多主机LAMP架构

常见的第三方php加速器

1、APC (Alternative PHP Cache)
遵循PHP License的开源框架,PHP opcode缓存加速器,目前的版本不适用于PHP 5.4
项目地址:http://pecl.php.net/package/APC

2、eAccelerator
源于Turck MMCache,早期的版本包含了一个PHP encoder和PHP loader,目前encoder已经不在支
持。项目地址 :http://eaccelerator.net/

3、XCache
快速而且稳定的PHP opcode缓存,经过严格测试且被大量用于生产环境。项目地址:http://xcache.lig
httpd.net/,收录EPEL源

4、Zend Optimizer和Zend Guard Loader
Zend Optimizer并非一个opcode加速器,它是由Zend Technologies为PHP5.2及以前的版本提供的一
个免费、闭源的PHP扩展,其能够运行由Zend Guard生成的加密的PHP代码或模糊代码。
而ZendGuard Loader则是专为PHP5.3提供的类似于Zend Optimizer功能的扩展。
项目地址http://www.zend.com/en/products/guard/runtime-decoders

5、NuSphere PhpExpress
NuSphere的一款开源PHP加速器,它支持装载通过NuSphere PHP Encoder编码的PHP程序文件,并
能够实现对常规PHP文件的执行加速。
项目地址,http://www.nusphere.com/products/phpexpress.htm

实现 xcache 加速 php 5.X

编译php-xcache加速访问,支持php 5.6版以下
官网:http://xcache.lighttpd.net/wiki/ReleaseArchive

案例:CentOS 7上安装清华源的php56,并编译安装 xcache加速
测试:在centos8中ab命令测试搭建的wordpress的并发速度
实验环境:
关闭防火墙和selinux。最小化安装的centos7:192.168.32.8

[root@centos7 ~]#ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:2e:a1:73 brd ff:ff:ff:ff:ff:ff
    inet 192.168.32.7/24 brd 192.168.32.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe2e:a173/64 scope link 
       valid_lft forever preferred_lft forever
[root@centos7 ~]#firewall-cmd --state
not running
[root@centos7 ~]#getenforce 
Disabled
[root@centos7 ~]#cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[root@centos7 ~]#

清华源官网

[root@centos7 ~]#yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/
remi-release-7.rpm


[root@centos7 ~]#yum install php56-php php56-php-mysqlnd mariadb-server -y


[root@centos7 ~]#ss -ntl
State       Recv-Q Send-Q           Local Address:Port                          Peer Address:Port              
LISTEN      0      128                          *:22                                       *:*                  
LISTEN      0      100                  127.0.0.1:25                                       *:*                  
LISTEN      0      128                         :::22                                      :::*                  
LISTEN      0      100                        ::1:25                                      :::*                  
[root@centos7 ~]#systemctl enable --now httpd mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to 
/usr/lib/systemd/system/httpd.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to 
/usr/lib/systemd/system/mariadb.service.
[root@centos7 ~]#ss -ntl
State       Recv-Q Send-Q           Local Address:Port                          Peer Address:Port              
LISTEN      0      50                           *:3306                                     *:*                  
LISTEN      0      128                          *:22                                       *:*                  
LISTEN      0      100                  127.0.0.1:25                                       *:*                  
LISTEN      0      128                         :::80                                      :::*                  
LISTEN      0      128                         :::22                                      :::*                  
LISTEN      0      100                        ::1:25                                      :::*                  
[root@centos7 ~]#

搭建wordpress服务创建数据库管理用户

[root@centos7 ~]#mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on wordpress.* to wordpress@'localhost' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye
[root@centos7 ~]#

wordpress官网
下载对应版本的安装包即可,这里选择wordpress-5.2.4-zh_CN.tar.gz

[root@centos7 ~]#ll
total 11544
-rw-------. 1 root root     1612 Dec  5 21:45 anaconda-ks.cfg
-rw-r--r--  1 root root      155 Dec  5 22:10 ifcfg-eth0
-rw-r--r--. 1 root root    11537 Nov  7 17:24 init.sh
-rw-r--r--  1 root root 11799512 Dec 12 16:25 wordpress-5.2.4-zh_CN.tar.gz

[root@centos7 ~]#tar xvf wordpress-5.2.4-zh_CN.tar.gz -C /var/www/html

[root@centos7 ~]#cd /var/www/html/
[root@centos7 html]#ll
total 4
drwxr-xr-x 5 1006 1006 4096 Nov 14 09:00 wordpress
[root@centos7 html]#chown -R apache.apache wordpress/
[root@centos7 html]#ll
total 4
drwxr-xr-x 5 apache apache 4096 Nov 14 09:00 wordpress
[root@centos7 html]#

访问对应页面,步骤化安装即可。
在这里插入图片描述
在这里插入图片描述
登入之后如上面页面,wordpress简单搭建成功。
在没有安装xcache加速之前先在centos8中测试一下访问wordpress的并发数

[root@centos8 ~]#ab -c 10 -n 100 http://192.168.32.7/wordpress/

在这里插入图片描述
下载并解压缩xcache-3.2.0.tar.bz2

Xcache官网下载

[root@centos7 ~]#ll
total 11716
-rw-------. 1 root root     1612 Dec  5 21:45 anaconda-ks.cfg
-rw-r--r--  1 root root      155 Dec  5 22:10 ifcfg-eth0
-rw-r--r--. 1 root root    11537 Nov  7 17:24 init.sh
-rw-r--r--  1 root root 11799512 Dec 12 16:25 wordpress-5.2.4-zh_CN.tar.gz
-rw-r--r--  1 root root   173368 Jun 20  2018 xcache-3.2.0.tar.gz
[root@centos7 ~]#tar xf xcache-3.2.0.tar.gz
[root@centos7 ~]#ll
total 11720
-rw-------.  1 root root     1612 Dec  5 21:45 anaconda-ks.cfg
-rw-r--r--   1 root root      155 Dec  5 22:10 ifcfg-eth0
-rw-r--r--.  1 root root    11537 Nov  7 17:24 init.sh
-rw-r--r--   1 root root 11799512 Dec 12 16:25 wordpress-5.2.4-zh_CN.tar.gz
drwxrwxr-x  17 1027  513     4096 Sep 19  2014 xcache-3.2.0
-rw-r--r--   1 root root   173368 Jun 20  2018 xcache-3.2.0.tar.gz

[root@centos7 ~]#yum -y install gcc php-devel      #安装编译需要的依赖包

[root@centos7 ~]#cd xcache-3.2.0
[root@centos7 xcache-3.2.0]#ll

在这里插入图片描述
在这里没有编译时候的configure脚本。这时候需要需要一个PHP工具phpize先生成configure脚本文件才行。

[root@centos7 xcache-3.2.0]#which phpize
/usr/bin/phpize
[root@centos7 xcache-3.2.0]#
[root@centos7 xcache-3.2.0]#/usr/bin/phpize    
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
#这个是用默认yum安装的PHP生成对应configure文件脚本,可能最后不兼容问题,建议使用编译安装的phpize程序路径,如下

假如没有phpize解决办法:

如果这个phpize没有,则需要去找寻这个那个包能够提供这个包。
在这里插入图片描述在这里插入图片描述

[root@centos7 xcache-3.2.0]#yum install php56-php-cli

在这里插入图片描述
找到phpize的路径之后,执行这个程序,生成对应的config文件
在运行这个程序之前还需要安装对应的工具包

[root@centos7 xcache-3.2.0]#yum install php56-php-devel -y

[root@centos7 xcache-3.2.0]#/opt/remi/php56/root/usr/bin/phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226

生成了对应的configure
在这里插入图片描述
编译安装:

[root@centos7 xcache-3.2.0]#./configure --enable-xcache
......省略部分
checking if cc supports -c -o file.o... (cached) yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
configure: creating ./config.status
config.status: creating config.h
config.status: executing libtool commands
[root@centos7 xcache-3.2.0]#

如果存在报错,提示说–with-phpconfig=/PATH,就要指定路径。这个路径是对应PHP程序的路径。
如何查找对应的路径:

[root@centos7 xcache-3.2.0]#find / -name "php-config*"
/usr/bin/php-config
/usr/share/man/man1/php-config.1.gz
/opt/remi/php56/root/usr/bin/php-config
/opt/remi/php56/root/usr/share/man/man1/php-config.1.gz
[root@centos7 xcache-3.2.0]#

其中/opt/remi/php56/root/usr/bin/php-config这个就是对应的php程序路径

[root@centos7 xcache-3.2.0]#./configure --enable-xcache --with-phpconfig=/opt/remi/php56/root/usr/bin
/php-config

编译make && make install

[root@centos7 xcache-3.2.0]#make && make install
......省略
libtool: install: cp ./.libs/xcache.lai /root/xcache-3.2.0/modules/xcache.la
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin" ldconfig -n /root/xcache-3.2.0/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /root/xcache-3.2.0/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the  -LLIBDIR 
flag during linking and do at least one of the following:
   - add LIBDIR to the  LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the  LD_RUN_PATH' environment variable
     during linking
   - use the  -Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/lib64/php/modules/   #提醒的模块编译放置位置

[root@centos7 xcache-3.2.0]#ls /usr/lib64/php/modules/
curl.so  fileinfo.so  json.so  phar.so  xcache.so  zip.so
[root@centos7 xcache-3.2.0]#

PHP调用对应 xcache.so 模块,需要复制或者追加到PHP支持模块的存放位置。

[root@centos7 ~]#find / -name "php.ini"
/etc/php.ini                           #yum默认安装的php程序模块路径
/opt/remi/php56/root/etc/php.ini       #编译安装的php程序模块路径

[root@centos7 xcache-3.2.0]#cat xcache.ini >> /opt/remi/php56/root/etc/php.ini
或者:
[root@centos7 xcache-3.2.0]#cp xcache.ini /opt/remi/php56/root/etc/php.d/

[root@centos7 xcache-3.2.0]#systemctl restart httpd
[root@centos7 xcache-3.2.0]#

检测是否加载成功:

[root@centos7 xcache-3.2.0]#cd /var/www/html/
[root@centos7 html]#vim test.php 
[root@centos7 html]#cat test.php 
<?php
phpinfo();
?>
[root@centos7 html]#

ctrl +F 搜索 xcache 找到说明加载成功。
在这里插入图片描述

在安装xcache加速之前先在centos8中测试一下访问wordpress的并发数

[root@centos8 ~]#ab -c 10 -n 100 http://192.168.32.7/wordpress/

在这里插入图片描述
优化了一点点。

opcache加速php 7.X

实验环境:基于已经默认安装的centos8 中yum安装部署的LAMP架构

  yum install php mariadb-server -y
  
  yum install php-mysqlnd
  
  systemctl start httpd
  
  systemctl start mariadb
  

搭建wordpress测试环境:

tar xf wordpress-5.2.4-zh_CN.tar.gz 
 
mv wordpress /var/www/html/
 
[root@centos8 html]#chown -R apache.apache wordpress/
 
create database wordpress;

grant all on wordpress.* to wordpress@'localhost' identified by 'centos';

访问网页,按照步骤安装登入即可。
在这里插入图片描述
部署好之后在centos7中测并发数

ab -c 10 -n 100 http://192.168.32.8/wordpress/

在这里插入图片描述

dnf install php-opcache
  Installing       : php-opcache-7.2.11-1.module_el8.0.0+56+d1ca79aa.x86_64               1/1 
  Running scriptlet: php-opcache-7.2.11-1.module_el8.0.0+56+d1ca79aa.x86_64               1/1 
  Verifying        : php-opcache-7.2.11-1.module_el8.0.0+56+d1ca79aa.x86_64               1/1 
Installed:
  php-opcache-7.2.11-1.module_el8.0.0+56+d1ca79aa.x86_64                                                           

Complete!

[root@centos8mini ~]#rpm -ql php-opcache
/etc/php.d/10-opcache.ini
/etc/php.d/opcache-default.blacklist
/usr/lib/.build-id
/usr/lib/.build-id/71
/usr/lib/.build-id/71/55ebb00f7ebcab9d708c1d5c7b7e634cce259c
/usr/lib64/php/modules/opcache.so
[root@centos8mini ~]#grep opcache /etc/php.d/10-opcache.ini 
zend_extension=opcache
opcache.enable=1
;opcache.enable_cli=0
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
;opcache.max_wasted_percentage=5
;opcache.use_cwd=1
;opcache.validate_timestamps=1
;opcache.revalidate_freq=2
;opcache.revalidate_path=0
;opcache.save_comments=1
;opcache.fast_shutdown=0
;opcache.enable_file_override=0
;opcache.optimization_level=0xffffffff
;opcache.inherited_hack=1
;opcache.dups_fix=0
opcache.blacklist_filename=/etc/php.d/opcache*.blacklist
;opcache.max_file_size=0
;opcache.consistency_checks=0
;opcache.force_restart_timeout=180
;opcache.error_log=
;opcache.log_verbosity_level=1
;opcache.preferred_memory_model=
;opcache.protect_memory=0
;opcache.restrict_api=
;opcache.file_cache=
;opcache.file_cache_only=0
;opcache.file_cache_consistency_checks=1
; Implies opcache.file_cache_only=1 for a certain process that failed to
;opcache.file_cache_fallback=1
;opcache.validate_permission=0
;opcache.validate_root=0
opcache.huge_code_pages=1
[root@centos8mini ~]#

[root@centos8mini ~]#systemctl restart httpd

再一次在centos7测试并发数

[root@centos7 ~]#ab -c 10 -n 100 http://192.168.32.8/wordpress/

在这里插入图片描述

php-fpm 模式实现LAMP

实现php-fpm模式

对于php请求,httpd可以用模块和fastcgi两种方式实现动态程序的支持。
fastcgi模式:php处理请求,不再由http服务器自身进行管理,http服务器把http协议转化为factcgi协
议,通过socket发送给fastcgi专用进程处理php程序
从稳定性上看,fastcgi是以独立的进程池运行来程序,如果单独一个进程死掉,系统可以很轻易的丢弃,然
后重新分配新的进程来运行逻辑。从安全性上看,fastcgi和http的server完全独立, fastcgi怎么down也不
会把server搞垮。
从性能上看,fastcgi把动态逻辑的处理从http server中分离出来,大负荷的IO处理还是留给宿主server,这
样hpttd server可以一心一意作IO,对于一个普通的动态网页来说,逻辑处理可能只有一小部分,大量的图
片等静态IO处理完全不需要逻辑程序的参与。从扩展性上讲,fastcgi是一个中立的技术标准,完全可以支
持任何语言写的处理程序,如php,java,python等。而php-fpm就是用来支持php的fastcgi服务器。

centos8默认为FCGI默认。
在centos7中要实现FCGI就需要安装php-fpm包

各种OS版本对fastcgi的支持
CentOS 8: 默认使用fpm模式

CentOS 7:
httpd-2.4:默认rpm包支持fcgi模块
php-fpm包:专用于将php运行于fpm模式

CentOS 6:
PHP-5.3.2之前:默认不支持fpm机制;需要自行打补丁并编译安装
httpd-2.2:默认不支持fcgi协议,需要自行编译此模块
解决方案:编译安装httpd-2.4, php-5.3.3+

安装php-fpm

CentOS 7 安装php-fpm

BASE源安装PHP-FPM

yum install php-fpm

清华大学yum源安装较新版的PHP-FPM(依赖EPEL源)

yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
#安装php-fpm5.6版
yum install php56-php-fpm php56-php-mysql
#安装php-fpm7.3版
yum install php73-php-fpm php73-php-mysql
CentOS 8 安装php-fpm

在之前不用FCGI模式的时候,安装php的时候会因为依赖性一起安装httpd,因为php是基于apache的模块方式。
但是这里用FCGI模式是独立的服务,所以httd需要自己手动安装。

[root@centos8 ~]#dnf install php-fpm php-mysqlnd mariadb-server httpd -y

配置php-fpm

查看php-fpm所对应的配置文件

[root@centos8 ~]#rpm -ql php-fpm       #列出主要的一些配置文件
/usr/lib/systemd/system/php-fpm.service
/etc/logrotate.d/php-fpm
/etc/php-fpm.conf
/etc/php-fpm.d
/etc/php-fpm.d/www.conf
/etc/sysconfig/php-fpm
/run/php-fpm

php-fpm 主要配置文件:
/etc/php-fpm.conf

/etc/php-fpm.d/*.conf

官方链接文档

PHP-FPM常见配置

daemonize = no //是否将程序运行在后台
listen = 127.0.0.1:9000 //FPM 监听地址
listen = /var/run/php.sock //UDF模式使用,指定生成的unix socket文件的路径
listen.owner = apache //UDF模式使用,指定生成的unix socket文件的所有者
listen.group = apache //UDF模式使用,指定生成的unix socket文件的所属组
listen.mode= 0666 //UDF模式使用,,指定生成的unix socket文件的权限
listen.acl_users = apache,nginx //指定用户访问unix socket文件,listen.owner 和listen.group将无效
listen.backlog = -1 //等待队列的长度 -1表示无限制
listen.allowed_clients = 127.0.0.1 //仅允许哪些主机访问
pm = dynamic|static //static 固定数量的子进程, //dynamic子进程数据以动态模式管理
pm.max_childen //static 固定数量的子进程
pm.start_servers
pm.min_spare_servers
pm.max_spare_servers
pm.max_requests = 500
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session //设置session存放位置

session目录
确保运行php-fpm进程的用户对session目录有读写权限
mkdir /var/lib/php/session
chown apache.apache /var/lib/php/session

启动PHP-FPM
systemctl start php-fpm

范例:php-fpm配置生产案例

cat /etc/php-fpm.d/www.conf
[www]
listen = 127.0.0.1:9000 #监听地址及IP
listen.allowed_clients = 127.0.0.1 #允许客户端从哪个源IP地址访问,要允许所有行首加 ;注释
即可
user = apache #php-fpm启动的用户和组,会涉及到后期文件的权限问题
group = apache
pm = dynamic #动态模式进程管理
pm.max_children = 500 #静态方式下开启的php-fpm进程数量,在动态方式下他限定php-fpm的最大进
程数
pm.start_servers = 100 #动态模式下初始进程数,必须大于等于pm.min_spare_servers和小于等
于pm.max_children的值。
pm.min_spare_servers = 100 #最小空闲进程数
pm.max_spare_servers = 200 #最大空闲进程数
pm.max_requests = 500000 #进程累计请求回收值,会重启
pm.status_path = /pm_status #状态访问URL
ping.path = /ping #ping访问动地址
ping.response = ping-pong #ping返回值
slowlog = /var/log/php-fpm/www-slow.log #慢日志路径
php_admin_value[error_log] = /var/log/php-fpm/www-error.log #错误日志
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files #phpsession保存方式及路径
php_value[session.save_path] = /var/lib/php/session #当时使用file保存session的文件
路径

部署不同主机的LAMP架构

三台不同的主机:
192.168.32.8 :部署HTTP
192.168.32.18:部署php的FCGI
192.168.32.28:部署数据库mariadb
实现基本上面实现部署wordpress

配置httpd 支持fastcgi

注意:在HTTPD服务器上必须启用proxy_fcgi_module模块,才能充当php-fpm客户端
实现httpd 支持fastcgi需要http的版本要在2.4.9或者更新,所以在centos7中配置httpd 支持fastcgi的话需要编译安装httpd。

UDS支持版本查看
在这里插入图片描述

[root@HTTP ~]#hostname HTTP

[root@HTTP ~]#dnf install httpd -y
......  
......
Installed:
  httpd-2.4.37-12.module_el8.0.0+185+5908b0db.x86_64                                                               
  apr-util-bdb-1.6.1-6.el8.x86_64                                                                                  
  apr-util-openssl-1.6.1-6.el8.x86_64                                                                              
  mailcap-2.1.48-3.el8.noarch                                                                                      
  apr-1.6.3-9.el8.x86_64                                                                                           
  apr-util-1.6.1-6.el8.x86_64                                                                                      
  centos-logos-httpd-80.5-2.el8.noarch                                                                             
  httpd-filesystem-2.4.37-12.module_el8.0.0+185+5908b0db.noarch                                                    
  httpd-tools-2.4.37-12.module_el8.0.0+185+5908b0db.x86_64                                                         
  mod_http2-1.11.3-3.module_el8.0.0+185+5908b0db.x86_64                                                            

Complete!

在配置文件中新建单独的一个子配置文件给fcgi服务使用

[root@HTTP ~]#vim /etc/httpd/conf.d/fcgi.conf

[root@HTTP ~]#cat /etc/httpd/conf.d/fcgi.conf
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.32.18:9000/data/php/$1
#以上开启FCGI反向代理,“^/”这处的”/“相对于后面的/data/php而言。后面的$1是指前面的/(.*.php)
#默认网页路径是/var/www/html,这里的路径需要和fastcgi中的测试.php文件保持一致。
[root@HTTP ~]#

检测是否有 proxy_fcgi_module 代理模块

[root@HTTP ~]#cat /etc/httpd/conf.modules.d/00-proxy.conf
# This file configures all the proxy modules:
LoadModule proxy_module modules/mod_proxy.so
LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so
LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_express_module modules/mod_proxy_express.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so         #需要这个模块已经加载
LoadModule proxy_fdpass_module modules/mod_proxy_fdpass.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
LoadModule proxy_uwsgi_module modules/mod_proxy_uwsgi.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
[root@HTTP ~]#

[root@HTTP ~]#httpd -M |grep fcgi
AH00558: httpd: Could not reliably determine the server's fully qualified domain name,
 using fe80::20c:29ff:fea5:3958. Set the 'ServerName' directive globally to suppress this 
 message
 proxy_fcgi_module (shared)
 
[root@HTTP ~]#systemctl start httpd
[root@HTTP ~]#ss -ntl
State         Recv-Q         Send-Q                  Local Address:Port                  Peer Address:Port         
LISTEN        0              128                           0.0.0.0:22                         0.0.0.0:*            
LISTEN        0              128                              [::]:22                            [::]:*            
LISTEN        0              128                                 *:80                               *:*            
[root@HTTP ~]#

可能出现The requested URL /wordpress/ was not found on this server.的问题
问题解决:
在主配置文件中增加index.php以及在/var/www/html/目录下新建一个wordpress文件夹,wordpress/wp-admin文件夹

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

<IfModule dir_module>
    DirectoryIndex index.php  index.html         #167行增加 index.php
</IfModule>

[root@HTTP ~]#mkdir /var/www/html/wordpress

[root@HTTP ~]#mkdir /var/www/html/wordpress/wp-admin

[root@HTTP ~]#systemctl restart httpd

配置部署fastcgi

[root@FCGI ~]#hostname FCGI

[root@FCGI ~]#dnf install php-fpm php-mysqlnd -y
......
......
Installed:
  php-fpm-7.2.11-1.module_el8.0.0+56+d1ca79aa.x86_64                                                               
  php-mysqlnd-7.2.11-1.module_el8.0.0+56+d1ca79aa.x86_64                                                           
  httpd-filesystem-2.4.37-12.module_el8.0.0+185+5908b0db.noarch                                                    
  nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch                                                   
  php-common-7.2.11-1.module_el8.0.0+56+d1ca79aa.x86_64                                                            
  php-pdo-7.2.11-1.module_el8.0.0+56+d1ca79aa.x86_64                                                               

Complete!

修改配置远程连接,配置:/etc/php-fpm.d/www.conf

;listen = /run/php-fpm/www.sock       #38行  注释掉sock传输  在后面新增新的监听端口
;listen=192.168.32.18:9000            #写法一:ip.add:port
listen=9000                           #写法二: port   这里选用写法二

; Default Value: any                  #默认任何主机都能连接
;listen.allowed_clients = 127.0.0.1   #63行   注释掉只能本机连接 

[root@FCGI ~]#ss -ntl
State         Recv-Q         Send-Q                  Local Address:Port                  Peer Address:Port         
LISTEN        0              128                           0.0.0.0:22                         0.0.0.0:*            
LISTEN        0              128                              [::]:22                            [::]:*            
[root@FCGI ~]#systemctl start php-fpm

[root@FCGI ~]#ss -ntl
State         Recv-Q         Send-Q                  Local Address:Port                  Peer Address:Port         
LISTEN        0              128                           0.0.0.0:22                         0.0.0.0:*            
LISTEN        0              128                              [::]:22                            [::]:*            
LISTEN        0              128                                 *:9000                             *:*            
[root@FCGI ~]#

如果依旧是sock连接,则看不到9000端口。
添加一个php测试页面:

[root@FCGI ~]#mkdir /data/php         #这里的测试路径需要和之前的httpd中fcgi.conf配置文件中路径保持一致
[root@FCGI ~]#vim /data/php/test.php
[root@FCGI ~]#cat /data/php/test.php 
<?php
phpinfo();

[root@FCGI ~]#

到这里先访问一下test.php文件是否能够访问
在这里插入图片描述

部署wordpress

部署wordpress是在主机192.168.32.18root@FCGI 上面部署

下载对应wordpress安装包:
wordpress官网

下载对应版本的安装包即可,这里选择wordpress-5.2.4-zh_CN.tar.gz

[root@FCGI ~]#ll
total 11540
-rw-------. 1 root root     1331 Dec  6 05:52 anaconda-ks.cfg
-rw-r--r--. 1 root root    11537 Nov  7 17:24 init.sh
-rw-r--r--  1 root root 11799512 Dec 12 16:25 wordpress-5.2.4-zh_CN.tar.gz
[root@FCGI ~]#
[root@FCGI ~]#tar xf wordpress-5.2.4-zh_CN.tar.gz -C /data/php/

[root@FCGI ~]#chown -R apache.apache /data/php/
[root@FCGI ~]#cd /data/php/
[root@FCGI php]#ll
total 8
-rw-r--r-- 1 apache apache   18 Dec 17 00:58 test.php
drwxr-xr-x 5 apache apache 4096 Nov 14 09:00 wordpress
[root@FCGI php]#

数据库安装部署

[root@MYSQL ~]#hostname MYSQL

[root@MYSQL ~]#yum install mariadb-server -y

[root@MYSQL ~]#systemctl start mariadb
[root@MYSQL ~]#ss -ntl
State         Recv-Q         Send-Q                  Local Address:Port                  Peer Address:Port         
LISTEN        0              128                           0.0.0.0:22                         0.0.0.0:*            
LISTEN        0              128                              [::]:22                            [::]:*            
LISTEN        0              80                                  *:3306                             *:*            
[root@MYSQL ~]#mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.11-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> grant all on wordpress.* to wordpress@'192.168.32.%' identified by 'centos';
Query OK, 0 rows affected (0.000 sec)
#这里不能是localhost,需要指定对应的主机。

MariaDB [(none)]> select user,host,password from mysql.user;
+-----------+--------------+-------------------------------------------+
| user      | host         | password                                  |
+-----------+--------------+-------------------------------------------+
| root      | localhost    |                                           |
| root      | mysql        |                                           |
| root      | 127.0.0.1    |                                           |
| root      | ::1          |                                           |
| wordpress | 192.168.32.% | *128977E278358FF80A246B5046F51043A2B1FCED |
+-----------+--------------+-------------------------------------------+
6 rows in set (0.001 sec)

MariaDB [(none)]> 

访问页面:http://192.168.32.8/wordpress进行安装即可

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
部署好了之后再重新访问:http://192.168.32.8/wordpress/
在这里插入图片描述
由于这里没有文件共享,访问的页面的数据仅仅是再192.168.32.18中的机器中的PHP数据。需要共享存储NFS解决此问题。

如果php-fpm和httpd在同一台主机,也可以用 UDS(unix domain socket)方式
默认就是UDS(unix domain socket)方式

ProxyPassMatch ^/(.*\.php)$
unix:/var/run/php.sock|fcgi://localhost/app/httpd24/htdocs/$1

fastcgi状态页和ping模块

fastcgi还支持状态页pm.status_path = /status和测试存活性ping.path = /ping
修改打开其设置:

[root@HTTP ~]#vim /etc/php-fpm.d/www.conf

pm.status_path = /status       #默认注释的 ,把注释取消

ping.path = /ping              #默认注释的 ,把注释取消

[root@HTTP ~]#vim /etc/httpd/conf.d/php.conf 
<IfModule !mod_php5.c>
  <IfModule !mod_php7.c>
    # Enable http authorization headers
    SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1

    <FilesMatch \.(php|phar)$>
        SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
    </FilesMatch>
    <Locationmatch /(status|ping) >                #增加其转发路径
        SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
    </locationmatch>

  </IfModule>
</IfModule>

[root@HTTP ~]#systemctl restart httpd

[root@HTTP ~]#systemctl restart php-fpm

在这里插入图片描述
在这里插入图片描述

还可以在后面加选项 ?full ?xml ?jons
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值