实验环境:
centos7.3主机一台
apache服务配置结束
官网下载最新版php源码包
实验前准备
]#yum install libxml2-devel -y]#yum install bzip2-devel -y]#yum install libmcrypt-devel -y <===基于epel源
编译安装
]#rz]#tar xvf php-7.1.10.tar.xz]#cd php-7.1.10/]#./configure --prefix=/app/php \--enable-mysqlnd \--with-mysqli=mysqlnd \--with-openssl \--with-pdo-mysql=mysqlnd \--enable-mbstring \--with-freetype-dir \--with-jpeg-dir \--with-png-dir \--with-zlib \--with-libxml-dir=/usr \ --enable-xml \--enable-sockets \--with-apxs2=/app/httpd24/bin/apxs \--with-mcrypt \--with-config-file-path=/etc \--with-config-file-scan-dir=/etc/php.d \--enable-maintainer-zts \--disable-fileinfo]#make && make install
添加配置文件
]#cd php-7.1.10/]#cp php.ini-production /etc/php.ini
编辑apache配置文件httpd.conf,以使apache支持php
]#vim /etc/httpd24/conf/httpd.confDirectoryIndex index.php index.html <===添加index.php一行AddType application/x-httpd-php .php <===添加以下两行AddType application/x-httpd-php-source .phps
测试
]#cd /app/httpd24/htdocs <===编译安装的主页在这里]#vim index.php ]#ab -c 10 -n 100 http://192.168.32.111/index.php <===另外一台主机测试服务器性能 ..Time per request: 21.902 [ms] (mean) Time per request: 2.190 [ms] (mean, across all concurrent requests)Transfer rate: 36964.69 [Kbytes/sec] received..
通过查看包组可以看到php的配置文件是在httpd下面,归httpd管理的一个小模块。能不能单独作为一个服务呢?当然可以。这就是fpm机制。
]#rpm -ql php/etc/httpd/conf.d/php.conf/etc/httpd/conf.modules.d/10-php.conf/usr/lib64/httpd/modules/libphp5.so/usr/share/httpd/icons/php.gif/var/lib/php/session
FPM机制
CentOS 6:
PHP-5.3.2之前:默认不支持fpm机制;需要自行打补丁并编译安装
httpd-2.2:默认不支持fcgi协议,需要自行编译此模块
解决方案:编译安装httpd-2.4, php-5.3.3+
CentOS 7:
httpd-2.4:rpm包默认编译支持了fcgi模块
php-fpm包:专用于将php运行于fpm模式
这里给大家介绍一下基于php-fpm包的fpm模式。
前提:卸载原来的php包,二者不能同时运行。
安装:
]#yum install -y php-fpm]#rpm -ql php-fpm/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/usr/lib/systemd/system/php-fpm.service/usr/lib/tmpfiles.d/php-fpm.conf/usr/sbin/php-fpm/usr/share/doc/php-fpm-5.4.16/usr/share/doc/php-fpm-5.4.16/fpm_LICENSE/usr/share/doc/php-fpm-5.4.16/php-fpm.conf.default/usr/share/fpm/usr/share/fpm/status.html/usr/share/man/man8/php-fpm.8.gz/var/log/php-fpm]#systemctl start php-fpm.service
添加配置文件
]#vim /etc/httpd24/httpd.conf <===在httpd配置文件中添加,我这里是编译安装的httpdDirectoryIndex index.phpProxyRequests Off <===是否开启正向代理ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1 <===开启FCGI反向代理注释:前面的/相对于后面的/var/www/html而言,后面的$1是指前面的/(.*\.php)
如果需要配置虚拟主机,把这段代码写进/etc/httpd/conf.d/vhosts.conf
<VirtualHost*:80>
.
.
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/b.net/$1
.
</VirtualHost>
注意:在HTTPD服务器上必须启用proxy_fcgi_module模块,充当PHP客户端。