适用于centos6.2以上版本,使用yum安装,session使用memcache保存,使用php-fpm管理PHPFastCGI,代码加速使用php-pecl-apc
shell自动安装脚本如下:
#安装基本模块yum -y install php php-fpm php-pear php-gd php-mbstring php-devel php-mcrypt php-mysqli php-pecl-apc php-curl#守护进程模式
sed -i 's/^daemonize/;&/' /etc/php-fpm.conf
#配制连接数(可以支持100并发)
sed -i 's/^;pm.max_children/&/' /etc/php-fpm.d/www.conf
sed -i 's/^pm.max_children/;&/' /etc/php-fpm.d/www.conf
sed -i '/^;pm.max_children/a\
pm.max_children = 100' /etc/php-fpm.d/www.conf
sed -i '/^;pm.max_children/d' /etc/php-fpm.d/www.conf
sed -i 's/^;pm.start_servers/&/' /etc/php-fpm.d/www.conf
sed -i 's/^pm.start_servers/;&/' /etc/php-fpm.d/www.conf
sed -i '/^;pm.start_servers/a\
pm.start_servers = 15' /etc/php-fpm.d/www.conf
sed -i '/^;pm.start_servers/d' /etc/php-fpm.d/www.conf
sed -i 's/^;pm.min_spare_servers/&/' /etc/php-fpm.d/www.conf
sed -i 's/^pm.min_spare_servers/;&/' /etc/php-fpm.d/www.conf
sed -i '/^;pm.min_spare_servers/a\
pm.min_spare_servers = 10' /etc/php-fpm.d/www.conf
sed -i '/^;pm.min_spare_servers/d' /etc/php-fpm.d/www.conf
sed -i 's/^;pm.max_spare_servers/&/' /etc/php-fpm.d/www.conf
sed -i 's/^pm.max_spare_servers/;&/' /etc/php-fpm.d/www.conf
sed -i '/^;pm.max_spare_servers/a\
pm.max_spare_servers = 20' /etc/php-fpm.d/www.conf
sed -i '/^;pm.max_spare_servers/d' /etc/php-fpm.d/www.conf
sed -i 's/^;pm.max_requests/&/' /etc/php-fpm.d/www.conf
sed -i 's/^pm.max_requests/;&/' /etc/php-fpm.d/www.conf
sed -i '/^;pm.max_requests/a\
pm.max_requests = 100' /etc/php-fpm.d/www.conf
sed -i '/^;pm.max_requests/d' /etc/php-fpm.d/www.conf
sed -i 's/^;request_terminate_timeout/&/' /etc/php-fpm.d/www.conf
sed -i 's/^request_terminate_timeout/;&/' /etc/php-fpm.d/www.conf
sed -i '/^;request_terminate_timeout/a\
request_terminate_timeout = 1s' /etc/php-fpm.d/www.conf
sed -i '/^;request_terminate_timeout/d' /etc/php-fpm.d/www.conf
#去掉配制session的地方
sed -i 's/php_value\[session/;&/' /etc/php-fpm.d/www.conf
#date
echo 'date.timezone = "Asia/Shanghai"' >> /etc/php.ini
sed -i '/^;include_path/a\
include_path = ".:/var/www/share"' /etc/php.ini
sed -i '/^;include_path/d' /etc/php.ini
#session
sed -i 's/^session.save_handler/;&/g' /etc/php.ini
sed -i '/^;session.save_handler/a\
session.save_handler = memcache' /etc/php.ini
sed -i '/^;session.save_handler/d' /etc/php.inised -i 's/^session.save_path/;&/g' /etc/php.ini
sed -i '/^;session\.save_path/a\
session.save_path = "tcp://127.0.0.1:11211?persistent=1&weight=1&timeout=1&retry_interval=15"' /etc/php.ini
sed -i '/^;session\.save_path/d' /etc/php.ini#配制自动启动
chkconfig --level 2345 php-fpm on#重新启动php-fpm
/etc/init.d/php-fpm restart
apc必须安装的,可以提高至少一倍的性能。
关于sed的使用,请参考 sed命令
如果要安装高版本的php,可以使用下面的yum源: