环境:CentOS 6.8
一、配置epel源,到阿里云镜像站下载对应版本的epel repo文件
http://mirrors.aliyun.com/help/epel
安装yum install bizp2-devel libmcrypt-devel – y
换回yum基本源安装:
yum install groupinstall " Development tools" -y
yum install groupinstall " Server Platform Development" -y
yum install libxml2 ibxml2-devel bzip2 bzip2-devel -y
二、解压php5.6.30 并进到php-5.6.30目录
./configure –prefix=/usr/local/php5 –with-mysql=/usr/local/mysql –with-openssl –with-mysqli=/usr/local/mysql/bin/mysql_config –enable-mbstring –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –enable-sockets –enable-fpm –with-mcrypt –with-config-file-path=/etc/php5/ –with-config-file-scan-dir=/etc/php5.d –with-bz2
三、执行 make -j 4 && make install
四、配置php-fpm
[root@system-4 php-5.6.30]# mkdir /etc/php5{,.d}
1、复制php.ini-production 到/etc/php5/php.ini
[root@system-4 php-5.6.30]# cp php.ini-production /etc/php5/php.ini
2、复制sapi/fpm/init.d.php-fpm到/etc/rc.d/init.d/php-fpm
[root@system-4 php-5.6.30]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
3、添加执行权限: chmod +x /etc/rc.d/init.d/php-fpm
4、添加php-fpm服务到开机启动项
chkconfig –add php-fpm
chkconfig php-fpm on
5、修改/usr/local/php5/etc下的配置文件
[root@system-4 etc]# cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
如果需要远程连接,修改监听为:listen = 0.0.0.0:9000
设置进程并发数,默认为5,pm.max_children = 50
刚开始的进程数,默认为2,pm.start_servers = 5
最少空闲进程数,默认为1,pm.min_spare_servers = 2
最少空闲进程数,默认为3,pm.max_spare_servers = 5
修改pid = /usr/local/php5/var/run/php-fpm.pid
[root@system-4 etc]# service php-fpm start
Starting php-fpm done
四、编辑httpd主配置文件vim /etc/httpd24/httpd.conf
1、启用下面的2个模块
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
2、配置虚拟主机或中心主机中支持使用fcgi
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/DocumentRoot目录/$1
编译安装httpd启用虚拟主机功能,主配置文件中添加:
Include /etc/httpd24/extra/httpd-vhosts.conf
编译安装的httpd默认的DocumentRoot=/usr/local/apache/htdocs
配置虚拟主机:
<VirtualHost *:80> DocumentRoot /var/www/html ServerName haha.com ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1
<Directory "/var/www/html"> Options none AllowOverride none Require all granted </Directory> </VirtualHost> |
echo "haha" > /var/www/html/index.html
重启httpd服务,在浏览器打开
虚拟主机已支持fcgi
3、在主配置文件中添加二行:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
4、修改DirectoryIndex index.php index.html