vim /usr/local/php/etc/php-fpm.conf //在[global]部分增加
include = etc/php-fpm.d/*.conf
mkdir /usr/local/php/etc/php-fpm.d/
cd /usr/local/php/etc/php-fpm.d/
vim www.conf //内容如下
[www]
listen = /tmp/php-fcgi.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 aming.conf //内容如下
[aming]
listen = /tmp/aming.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
/usr/local/php/sbin/php-fpm –t
/etc/init.d/php-fpm restart
[root@linux-01 aming.com]# cd /usr/local/php-fpm/etc/
[root@linux-01 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[root@linux-01 etc]# cat 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
[www]
listen = /tmp/php-fcgi.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
[root@linux-01 etc]# vim php-fpm.conf
添加一下内容
[aming.com]
listen = /tmp/aming.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
[root@linux-01 etc]# /usr/local/php-fpm/sbin/php-fpm -t
[29-Mar-2018 06:33:41] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@linux-01 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm done
[root@linux-01 etc]# ps aux | grep -i php-fpm //多了一个aming.com
[root@linux-01 etc]# cd /usr/local/nginx/conf/vhost/
[root@linux-01 vhost]# ls
aaa.com.conf load.conf proxy.conf ssl.conf test.com.conf
[root@linux-01 vhost]# vi aaa.com.conf
//添加location php部分
server
{
listen 80 default_server;
server_name aaa.com;
index index.html index.htm index.php;
root /data/wwwroot/default;
location ~ \.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/aming.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name;
}
}
多个pool,有的网址无法访问时,别的网页不受影响
[root@linux-01 ~]# cd /usr/local/php-fpm/etc/
[root@linux-01 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[root@linux-01 etc]# vim 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
[root@linux-01 etc]# mkdir php-fpm.d
[root@linux-01 etc]# cd php-fpm.d/
[root@linux-01 php-fpm.d]# vim aming.conf
[aming.com]
listen = /tmp/aming.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
[root@linux-01 php-fpm.d]# vim www.conf
[www]
listen = /tmp/php-fcgi.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
[root@linux-01 php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
[29-Mar-2018 07:00:43] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@linux-01 php-fpm.d]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@linux-01 php-fpm.d]# ps aux |grep php-fpm
配置成多个pool 池子后,和原来的一个php-fpm.conf配置多个pool效果一样
12.22 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
配置nginx的虚拟主机test.com.conf,把unix:/tmp/php-fcgi.sock改为unix:/tmp/www.sock
重新加载nginx服务
vim /data/wwwroot/test.com/sleep.php //写入如下内容
<?php echo “test slow log”;sleep(2);echo “done”;?>
curl -x127.0.0.1:80 test.com/sleep.php
cat /usr/local/php-fpm/var/log/www-slow.log
操作过程
[root@linux-01 php-fpm.d]# vim www.conf
//添加如下内容
request_slowlog_timeout = 1
slowlog = /usr/local/php-fpm/var/log/www-slow.log
[root@linux-01 php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
[29-Mar-2018 07:08:29] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@linux-01 php-fpm.d]# /etc/init.d/php-fpm reload
[root@linux-01 php-fpm.d]# ls /usr/local/php-fpm/var/log/www-slow.log
/usr/local/php-fpm/var/log/www-slow.log
[root@linux-01 php-fpm.d]# vim /data/wwwroot/test.com/sleep.php
<?php
echo "test slow log";
sleep(2);
echo "done";
?>
[root@linux-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php
停顿2秒
[root@linux-01 php-fpm.d]# cat /usr/local/php-fpm/var/log/www-slow.log
[29-Mar-2018 08:26:51] [pool www] pid 15527
script_filename = /data/wwwroot/test.com/sleep.php
[0x00007f1e35886298] sleep() /data/wwwroot/test.com/sleep.php:3
12.23 open_basedir
vim /usr/local/php-fpm/etc/php-fpm.d/aming.conf //加入如下内容
php_admin_value[open_basedir]=/data/wwwroot/aming.com:/tmp/
创建测试php脚本,进行测试
再次更改aming.conf,修改路径,再次测试
配置错误日志
再次测试
查看错误日志
php-fcgi.sock
操作过程
[root@linux-01 php-fpm.d]# vim www.conf //添加一下内容
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
[root@linux-01 php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
[29-Mar-2018 08:32:55] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@linux-01 php-fpm.d]# /etc/init.d/php-fpm reloa
[root@linux-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php
显示phpinfo网页信息
12.24 php-fpm进程管理
pm = dynamic //动态进程管理,也可以是static
pm.max_children = 50 //最大子进程数,ps aux可以查看
pm.start_servers = 20 //启动服务时会启动的进程数
pm.min_spare_servers = 5 //定义在空闲时段,子进程数的最少数量,如果达到这个数值时,php-fpm服务会自动派生新的子进程。
pm.max_spare_servers = 35 //定义在空闲时段,子进程数的最大值,如果高于这个数值就开始清理空闲的子进程。
pm.max_requests = 500 //定义一个子进程最多处理的请求数,也就是说在一个php-fpm的子进程最多可以处理这么多请求,当达到这个数值时,它会自动退出。
原文:http://blog.51cto.com/9298822/2111044