1、系统环境:
[[email protected] ~]# cat /etc/issue CentOS release 6.4 (Final) Kernel \r on an \m [[email protected] ~]# uname -r 2.6.32-358.el6.x86_64 [[email protected] ~]# ifconfig | grep Bcast: inet addr:192.168.0.200 Bcast:192.168.0.255 Mask:255.255.255.0
2、httpd 2.4源码安装:
请猛戳:httpd 2.4源码安装
3、mysql 5.5通用二进制包安装:
4、编译安装php,开启fpm:
[[email protected] php-5.5.20]# pwd /root/software/php/php-5.5.20 [[email protected] php-5.5.20]# ./configure --prefix=/usr/local/php5.5 --enable-mbstring --enable-xml --enable-fpm --enable-sockets --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 #--enable-fpm 开启php-fpm #--enable-maintainer-zts 此选项已删除,因php是已独立方式运行 [[email protected] php-5.5.20]# make && make install
为php提供配置文件、为php-fpm提供配置文件及为php-fpm提供启用脚本:
[[email protected] php-5.5.20]# cp php.ini-production /etc/php.ini [[email protected] php-5.5.20]# cp /usr/local/php5.5/etc/php-fpm.conf.default /usr/local/php5.5/etc/php-fpm.conf [[email protected] php-5.5.20]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm [[email protected] php-5.5.20]# chmod +x /etc/rc.d/init.d/php-fpm [[email protected] php-5.5.20]# chkconfig --add php-fpm [[email protected] php-5.5.20]# chkconfig --list php-fpm php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
启动php-fpm及验证php-fpm服务:
[[email protected] php-5.5.20]# service php-fpm start Starting php-fpm done [[email protected] php-5.5.20]# ps aux | grep php-fpm
5、配置httpd,让其成为fastcgi客户端,并把httpd配置成虚拟主机方式工作:
启用mod_proxy.so及mod_proxy_fcgi.so两个模块:
[[email protected] php-5.5.20]# vim /etc/httpd24/httpd.conf ……省略 LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so ……省略
配置httpd.conf文件,让其对php文件的支持:
[[email protected] php-5.5.20]# vim /etc/httpd24/httpd.conf ……省略 AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType application/x-httpd-php .php #新增 AddType application/x-httpd-php-source .phps #新增 ……省略 <IfModule dir_module> DirectoryIndex index.php index.html #新增index.php </IfModule>
停用中心主机,并启用虚拟主机的支持:
[[email protected] php-5.5.20]# vim /etc/httpd24/httpd.conf #DocumentRoot "/usr/local/apache24/htdocs" #注释此行,关闭中心主机 …… # Virtual hosts Include /etc/httpd24/extra/httpd-vhosts.conf #启用此行,开启虚拟主机文件
配置虚拟主机配置文件:
[[email protected] php-5.5.20]# vim /etc/httpd24/extra/httpd-vhosts.conf #注释最后的</VirtualHost>容器,在最后新增下面配置: <VirtualHost *:80> DocumentRoot "/web/zhaochj.com" ServerName www.zhaochj.com ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/web/zhaochj.com/$1 <Directory "/web/zhaochj.com"> Options none AllowOverride none Require all granted </Directory> </VirtualHost>
准备网页文件目录,建立测试页面:
[[email protected] php-5.5.20]# mkdir -p /web/zhaochj.com [[email protected] php-5.5.20]# vim /web/zhaochj.com/index.php <?php phpinfo(); ?>
重新启动httpd:
[[email protected] php-5.5.20]# /usr/local/apache24/bin/apachectl -k stop [[email protected] php-5.5.20]# /usr/local/apache24/bin/apachectl -t Syntax OK [[email protected] php-5.5.20]# /usr/local/apache24/bin/apachectl -k start
访问测试页面:
6、优化php5,启用php5自带的代码缓冲机制opcache,不再使用xcache了:
[[email protected] php-5.5.20]# vim /etc/php.ini ……省略 [opcache] zend_extension = /usr/local/php5.5/lib/php/extensions/no-debug-non-zts-20121212/opcache.so opcache.enable=1 opcache.memory_consumption = 64 opcache.interned_strings_buffer = 8 opcache.max_accelerated_files = 4000 opcache.revalidate_freq = 60 opcache.fast_shutdown = 1 opcache.enable_cli = 1 ……省略
重新启动php-fpm:
[[email protected] php-5.5.20]# service php-fpm restart
测试opcache是否启用:
[[email protected] php-5.5.20]# /usr/local/php5.5/bin/php -m
时间: 2024-10-31 22:59:18