4.php-fpm配置
4.1php-fpm的pool
Nginx可以配置多个虚拟主机,同样php-fpm同样也支持配置多个pool,每一个pool可以监听一个端口,也可以监听一个socket。现在把php-fpm.conf做一个更改,内容如下:
[global] pid = /usr/local/php-fpm/var/run/php-fpm.pid error_log = /usr/local/php-fpm/var/log/php-fpm.log include = etc/php-fpm.d/*.conf //等号后面的路径上必须写上etc,然后创建需要的配置文件目录和子配置文件 [www] listen = /tmp/php-fcgi.sock listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 100 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 50 rlimit_files = 1024
创建配置文件目录和子配置文件:
# mkdir /usr/local/php-fpm/etc/php-fpm.d # cd /usr/local/php-fpm/etc/php-fpm.d/ # vim www.conf
[www]
listen = /tmp/www.sock
listen.mode=666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
保存后,在编辑另外的配置文件:
# vim yu.conf
[yu]
listen = /tmp/yu.sock
listen.mode=666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers =35
pm.max_requests = 500
rlimit_files = 1024
这样就有了两个子配置文件,也就是等于有两个pool了,第一个pool监听了/tmp/www.sock第二个pool监听了/tmp/yu.sock。这样就能在Nginx不同的虚拟主机中调用不同的pool,从而达到相互隔离的目的。
# /usr/local/php-fpm/sbin/php-fpm -t //验证配置是否有问题
# /etc/init.d/php-fpm restart //重启php-fpm服务
Gracefully shutting down php-fpm . done
Starting php-fpm done
4.2php-fpm的慢执行日志
开启和查看php-fpm的慢执行日志:
# vim /usr/local/php-fpm/etc/php-fpm.d/www.conf //在后面写入以下两行
request_slowlog_timeout = 1 //定义超时时间,即在脚本执行时超出一秒就是被记录日志。 slowlog = /usr/local/php-fpm/var/log/www-slow.log //定义慢执行日志的路径和名字。
4.3phpfpm定义open_basedir
php可以针对不同的pool设置不同的open_basedir。
# vim /usr/local/php-fpm/etc/php-fpm.d/yu.conf //在文件后添加以下内容
php_yu_calue[open_basedir]=/data/www/:/tmp/