12.21 php-fpm的pool
[[email protected] ~]# cd /usr/local/php-fpm/etc/
[[email protected] etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[[email protected] 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 = 127.0.0.1:9000
listen.mode = 444
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
[[email protected] etc]#
重新配置配置文件,重新添加一个pool pool ,名字叫aaa.com
nginx有多个pool
[[email protected] etc]# vim !$
vi php-fpm.conf
[www]
listen = /tmp/php-fcgi.sock
#listen = 127.0.0.1:9000
listen.mode = 444
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
[aaa.com]
listen = /tmp/aaa.com.sock
#listen = 127.0.0.1:9000
listen.mode = 444
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
:wq
[[email protected] etc]# /usr/local/php-fpm/sbin/php-fpm -t
[30 Jan 2018 20:58:41] NOTICE: PHP message: PHP Deprecated: Comments starting with ‘#‘ are deprecated in Unknown on line 1 in Unknown on line 0
[30 Jan 2018 20:58:41] NOTICE: PHP message: PHP Deprecated: Comments starting with ‘#‘ are deprecated in Unknown on line 1 in Unknown on line 0
[30 Jan 2018 20:58:41] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[[email protected] etc]# /etc/init.d/php-fpm reload
Reload service php-fpm done
检查下,重新加载
最右侧多了一个aaa.com pool,
[[email protected] etc]# ps aux |grep php-fpm
root 2410 0.0 0.4 227216 4960 ? Ss 21:02 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 2411 0.0 0.4 227156 4716 ? S 21:02 0:00 php-fpm: pool www
php-fpm 2412 0.0 0.4 227156 4716 ? S 21:02 0:00 php-fpm: pool www
php-fpm 2413 0.0 0.4 227156 4716 ? S 21:02 0:00 php-fpm: pool www
php-fpm 2414 0.0 0.4 227156 4716 ? S 21:02 0:00 php-fpm: pool www
php-fpm 2415 0.0 0.4 227156 4720 ? S 21:02 0:00 php-fpm: pool www
php-fpm 2416 0.0 0.4 227156 4720 ? S 21:02 0:00 php-fpm: pool www
php-fpm 2442 0.0 0.4 227156 4728 ? S 21:02 0:00 php-fpm: pool aaa.com
php-fpm 2443 0.0 0.4 227156 4728 ? S 21:02 0:00 php-fpm: pool aaa.com
php-fpm 2444 0.0 0.4 227156 4728 ? S 21:02 0:00 php-fpm: pool aaa.com
php-fpm 2445 0.0 0.4 227156 4728 ? S 21:02 0:00 php-fpm: pool aaa.com
php-fpm 2446 0.0 0.4 227156 4728 ? S 21:02 0:00 php-fpm: pool aaa.com
php-fpm 2447 0.0 0.4 227156 4728 ? S 21:02 0:00 php-fpm: pool aaa.com
php-fpm 2448 0.0 0.4 227156 4728 ? S 21:02 0:00 php-fpm: pool aaa.com
php-fpm 2449 0.0 0.4 227156 4728 ? S 21:02 0:00 php-fpm: pool aaa.com
php-fpm 2450 0.0 0.4 227156 4728 ? S 21:02 0:00 php-fpm: pool aaa.com
root 2476 0.0 0.0 112680 980 pts/0 R+ 21:04 0:00 grep --color=auto php-fpm
[[email protected] etc]#
现在怎么去用它们呢
为什么要定义多个 pool,加入test.com 请求很大,最终把进程耗尽了php-fpm ,最多启动50个,结果启动完50个 所有的都在忙,又有新的请求的时候,结果就报502错误,因为他没有多余的php 进程给它提供服务,而这个站点不受影响,因为他用的是另一个 pool,这就是为什么要定义多个 pool的原因。
[[email protected] vhost]# vim aaa.com.conf
[1]+ 已停止 vi aaa.com.conf
[[email protected] vhost]# cat test.com.conf
[[email protected] vhost]# fg
vi aaa.com.conf
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/aaa.com.sock;
fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name;
}
}
~
~
~
:wq
在主配置文件里面 加入 include = etc/php-fpm.d/*.conf 加入到[global]里面,然后再把[www]和[global]分别拆出来
[[email protected] vhost]# ls
aaa.com.conf ld.conf proxy.conf ssl.conf test.com.conf
[[email protected] vhost]# cd /usr/local/php-fpm/etc/
[[email protected] etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[[email protected] 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
[www]
listen = /tmp/php-fcgi.sock
#listen = 127.0.0.1:9000
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
[aaa.com]
listen = /tmp/aaa.com.sock
#listen = 127.0.0.1:9000
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
:wq
[[email protected] 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
include = etc/php-fpm.d/*.conf
[www]
listen = /tmp/php-fcgi.sock
#listen = 127.0.0.1:9000
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
[aaa.com]
listen = /tmp/aaa.com.sock
#listen = 127.0.0.1:9000
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
[[email protected] etc]#
然后再把这些删掉,100dd 就是删除下面100行,实际只有27行
[[email protected] 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
~
~
:wq
[[email protected] etc]# vim php-fpm.conf
因为是include = etc/php-fpm.d/*.conf 所以要创建一个php-fpm.d的目录
然后再创建一个php-fpm.d的目录 再去目录里面创建 www.conf aaa.com.conf
[[email protected] etc]# mkdir php-fpm.d
[[email protected] etc]# cd php-fpm.d/
[[email protected] php-fpm.d]#
[[email protected] php-fpm.d]# vim www.conf
[www]
listen = /tmp/php-fcgi.sock
#listen = 127.0.0.1:9000
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
~
~
~
:wq
[[email protected] php-fpm.d]# vim aaa.com.conf
[aaa.com]
listen = /tmp/aaa.com.sock
#listen = 127.0.0.1:9000
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
[[email protected] etc]# vim php-fpm.conf
[[email protected] etc]# mkdir php-fpm.d
[[email protected] etc]# cd php-fpm.d/
[[email protected] php-fpm.d]# vim www.conf
[[email protected] php-fpm.d]# vim aaa.com.conf
~
:wq
[[email protected] etc]# vim php-fpm.conf
[[email protected] etc]# mkdir php-fpm.d
[[email protected] etc]# cd php-fpm.d/
[[email protected] php-fpm.d]# vim www.conf
[[email protected] php-fpm.d]# vim aaa.com.conf
[[email protected] php-fpm.d]# ls
aaa.com.conf www.conf
[[email protected] php-fpm.d]#
这样看着就很干净了,这个类似于nginx的vhost
[[email protected] php-fpm.d]# 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
include = etc/php-fpm.d/*.conf
[[email protected] php-fpm.d]#
再检查配置文件重启下
[[email protected] php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
[29 Jan 2018 23:54:28] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[[email protected] php-fpm.d]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[[email protected] php-fpm.d]#
[[email protected] php-fpm.d]# !ps
ps aux |grep php-fpm
root 5927 0.0 0.4 227240 4980 ? Ss 23:54 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 5928 0.0 0.4 227180 4720 ? S 23:54 0:00 php-fpm: pool aaa.com
php-fpm 5929 0.0 0.4 227180 4724 ? S 23:54 0:00 php-fpm: pool aaa.com
php-fpm 5930 0.0 0.4 227180 4724 ? S 23:54 0:00 php-fpm: pool aaa.com
php-fpm 5931 0.0 0.4 227180 4724 ? S 23:54 0:00 php-fpm: pool aaa.com
php-fpm 5932 0.0 0.4 227180 4728 ? S 23:54 0:00 php-fpm: pool aaa.com
php-fpm 5933 0.0 0.4 227180 4728 ? S 23:54 0:00 php-fpm: pool aaa.com
php-fpm 5934 0.0 0.4 227180 4728 ? S 23:54 0:00 php-fpm: pool aaa.com
php-fpm 5962 0.0 0.4 227180 4736 ? S 23:54 0:00 php-fpm: pool www
php-fpm 5963 0.0 0.4 227180 4736 ? S 23:54 0:00 php-fpm: pool www
php-fpm 5964 0.0 0.4 227180 4736 ? S 23:54 0:00 php-fpm: pool www
php-fpm 5965 0.0 0.4 227180 4736 ? S 23:54 0:00 php-fpm: pool www
php-fpm 5966 0.0 0.4 227180 4736 ? S 23:54 0:00 php-fpm: pool www
php-fpm 5967 0.0 0.4 227180 4736 ? S 23:54 0:00 php-fpm: pool www
root 5969 0.0 0.0 112680 980 pts/0 S+ 23:55 0:00 grep --color=auto php-fpm
[[email protected] php-fpm.d]#
以上就是多个pool的配置
12.22 php-fpm慢执行日志
如果做PHP得网站,建议使用LNMP,其中有一个原因在于我们可以去分析php的慢执行日志,为什么要分析它的 慢执行日志呢,运维工作中,经常会遇到一个问题
老板会经常反馈,你们公司的网站访问慢了,或者客户说网站慢了,要知道根本原因,要知道慢在什么地方,java网站先不说,php的网站有是办法查到底慢在哪里,就像系统负载高可以用工具去分析,vmstat top 等等,可以找到哪个进程导致的,php网站慢,到底什么地方慢,所以这个慢日志,非常重要,
针对www做一个实验
[[email protected] 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
request_slowlog_timeout = 1 //超过1秒钟 我就要记录日志
slowlog = /usr/local/php-fpm/var/log/www-slow.log //日志放在这个目录下
~
~
:wq
[[email protected] php-fpm.d]# vim www.conf
[[email protected] php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
[30 Jan 2018 00:06:45] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[[email protected] php-fpm.d]# /etc/init.d/php-fpm reload
Reload service php-fpm done
[[email protected] php-fpm.d]#
先看下日志有没有生成 有的 www-slow.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
request_slowlog_timeout = 1
slowlog = /usr/local/php-fpm/var/log/www-slow.log
[[email protected] php-fpm.d]# ls /usr/local/php-fpm/var/log/
php-fpm.log www-slow.log
[[email protected] php-fpm.d]#
[[email protected] php-fpm.d]# ls /usr/local/php-fpm/var/log/www-slow.log
/usr/local/php-fpm/var/log/www-slow.log
[[email protected] php-fpm.d]# cat !$
cat /usr/local/php-fpm/var/log/www-slow.log
[[email protected] php-fpm.d]#
看看它有没有内容呢,空的,因为你还没有任何的超过1秒的 php执行的过程
接下来需要模拟一个慢执行的php
来写一个脚本
php-fcgi 它是被这个(/usr/local/nginx/conf/vhost/test.com.conf
) test.com.conf站点用着 fastcgi_pass unix:/tmp/php-fcgi.sock;
所以你要去这个站点做一些操作了,在这个目录下/data/wwwroot/test.com
[[email protected] php-fpm.d]# vim /data/wwwroot/test.com/sleep.php
<?php
echo “test slow log”;
sleep(2);
echo “done”;
?>
:wq
来测试下
[[email protected] php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php -I
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Mon, 29 Jan 2018 16:19:16 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30
[[email protected] php-fpm.d]#
出错误了,排查错误看日志,也有个简单的方法,直接打开它的配置文件,搜索display_error 把display_errors = On
可以直接查看到具体的错误是什么
[[email protected] php-fpm.d]# vim /usr/local/php-fpm/etc/php.ini
; development version only in development environments, as errors shown to
; application users can inadvertently leak otherwise secure information.
; This is php.ini-development INI file.
;;;;;;;;;;;;;;;;;;;
; Quick Reference ;
;;;;;;;;;;;;;;;;;;;
; http://php.net/display-errors
display_errors = On
[[email protected] php-fpm.d]# vim /usr/local/php-fpm/etc/php.ini
[[email protected] php-fpm.d]# /etc/init.d/php-fpm reload
Reload service php-fpm done
[[email protected] php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php
<br />
<b>Parse error</b>: syntax error, unexpected ‘slow‘ (T_STRING), expecting ‘,‘ or ‘;‘ in <b>/data/wwwroot/test.com/sleep.php</b> on line <b>2</b><br />
[[email protected] php-fpm.d]#
提示语法错误,分号不对,双引号不对,进去改下
[[email protected] php-fpm.d]# vim /data/wwwroot/test.com/sleep.php
<?php
echo "test slow log";
sleep(2);
echo "done";
?>
:wq
再来测试下,它会告诉你是这个脚本慢,脚本的第三行慢 /data/wwwroot/test.com/sleep.php:3
[[email protected] php-fpm.d]# vim /data/wwwroot/test.com/sleep.php
[[email protected] php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php
test slow logdone
[[email protected] php-fpm.d]# cat /usr/local/php-fpm/var/log/www-slow.log
[30 Jan 2018 00:29:29] [pool www] pid 6123
script_filename = /data/wwwroot/test.com/sleep.php
[0x00007f06da03d298] sleep() /data/wwwroot/test.com/sleep.php:3
[[email protected] php-fpm.d]#
看下第三行 sleep(2); 是这一行,因为它执行了2秒钟,只要超过了1秒就会被记录慢日志,这就是慢日志的功效了
[[email protected] php-fpm.d]# cat /data/wwwroot/test.com/sleep.php
<?php
echo "test slow log";
sleep(2);
echo "done";
?>
[[email protected] php-fpm.d]#
这样就可以生成慢日志
12.23 open_basedir
open_bassdir 之前也介绍了,在php-fpm 也可以定义的,如果你服务器上有多个网站,去php.ini就不合适了,所以要么去apache虚拟主机配置文件里定义,要么去php-fpm配置文件里去定义,可以针对每个 pool做不同的定义
比如我在www里面去定义
[[email protected] 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
request_slowlog_timeout = 1
slowlog = /usr/local/php-fpm/var/log/www-slow.log
php_admin_value[open_basedir]=/data/wwwroot/aaa.com:/tmp/
~
:wq
[[email protected] php-fpm.d]# cat 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
request_slowlog_timeout = 1
slowlog = /usr/local/php-fpm/var/log/www-slow.log
php_admin_value[open_basedir]=/data/wwwroot/aaa.com:/tmp/
[[email protected] php-fpm.d]#
正常的话/tmp/php-fcgi.sock 是test.com,定义成aaa.com 的话,去请求去访问php,肯定会出问题
重启下
[[email protected] php-fpm.d]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[[email protected] php-fpm.d]#
[[email protected] php-fpm.d]# !curl
curl -x127.0.0.1:80 test.com/sleep.php
No input file specified.
[[email protected] php-fpm.d]# !netstat
netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5682/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 874/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1783/master
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 5682/nginx: master
tcp6 0 0 :::3306 :::* LISTEN 1578/mysqld
tcp6 0 0 :::22 :::* LISTEN 874/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1783/master
[[email protected] php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php -I
HTTP/1.1 404 Not Found
Server: nginx/1.12.1
Date: Mon, 29 Jan 2018 17:07:37 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30
[[email protected] php-fpm.d]#
404肯定就不对了,所以说是有问题的
[[email protected] php-fpm.d]# cat 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
request_slowlog_timeout = 1
slowlog = /usr/local/php-fpm/var/log/www-slow.log
php_admin_value[open_basedir]=/data/wwwroot/aaa.com:/tmp/
[[email protected] php-fpm.d]#
现在我们再去定义一个php
[[email protected] php-fpm.d]# vim /usr/local/nginx/conf/vhost/test.com.conf
[[email protected] php-fpm.d]# vim /data/wwwroot/test.com/
1.gif 2.js 3.php admin/ index.html sleep.php upload/
[[email protected] php-fpm.d]# vim /data/wwwroot/test.com/3.php
[[email protected] php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php -I
HTTP/1.1 404 Not Found
Server: nginx/1.12.1
Date: Mon, 29 Jan 2018 17:12:18 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30
[[email protected] php-fpm.d]# !vi www.conf
vi /data/wwwroot/test.com/3.php www.conf
2 files to edit
[[email protected] php-fpm.d]# ls
aaa.com.conf www.conf
[[email protected] php-fpm.d]# vim www.conf
修改下www.conf,你针对的地方是test.com 如果这个地方不去定义正确的路径, 他就没办法去访问
[[email protected] 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
request_slowlog_timeout = 1
slowlog = /usr/local/php-fpm/var/log/www-slow.log
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
~
~
~
:wq
[[email protected] php-fpm.d]# vim www.conf
[[email protected] php-fpm.d]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[[email protected] php-fpm.d]# !curl
curl -x127.0.0.1:80 test.com/3.php -I
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Mon, 29 Jan 2018 17:17:29 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30
[[email protected] php-fpm.d]#
[[email protected] php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php
e PHP License as published by the PHP Group and included in the distribution in the file: LICENSE
</p>
<p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
</p>
<p>If you did not receive a copy of the PHP license, or have any questions about PHP licensing, please contact [email protected]
</p>
</td></tr>
</table>
</div></body></html>[[email protected] php-fpm.d]#
查看下错误日志
[[email protected] php-fpm.d]# vim /usr/local/php-fpm/etc/php.ini
; http://php.net/display-errors
display_errors = Off
; Log errors to syslog (Event Log on Windows).
;error_log = syslog
error_log = /usr/local/php-fpm/var/log/php_errors.log
;error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
error_reporting =E_ALL
[[email protected] php-fpm.d]# vim /usr/local/php-fpm/etc/php.ini
[[email protected] php-fpm.d]#
把地址改错,会生成错误日志
[[email protected] 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
request_slowlog_timeout = 1
slowlog = /usr/local/php-fpm/var/log/www-slow.log
php_admin_value[open_basedir]=/data/wwwroot/wwtest.com:/tmp/
~
~
:wq
[[email protected] php-fpm.d]# vim /usr/local/php-fpm/etc/php.ini
[[email protected] php-fpm.d]# ls
aaa.com.conf www.conf
[[email protected] php-fpm.d]# vim www.conf
[[email protected] php-fpm.d]# grep error_log /usr/local/php-fpm/etc/php.ini
; server-specific log, STDERR, or a location specified by the error_log
; Set maximum length of log_errors. In error_log information about the source is
;error_log = php_errors.log
;error_log = syslog
error_log = /usr/local/php-fpm/var/log/php_errors.log
; OPcache error_log file name. Empty string assumes "stderr".
;opcache.error_log=
[[email protected] php-fpm.d]# ls /usr/local/php-fpm/var/log/
php-fpm.log www-slow.log
[[email protected] php-fpm.d]# touch /usr/local/php-fpm/var/log/php_errors.log
[[email protected] php-fpm.d]# chmod 777 /usr/local/php-fpm/var/log/php_errors.log
[[email protected] php-fpm.d]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
来访问下
[[email protected] php-fpm.d]# !curl
curl -x127.0.0.1:80 test.com/3.php
No input file specified.
[[email protected] php-fpm.d]#
[[email protected] php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php -I
HTTP/1.1 404 Not Found
Server: nginx/1.12.1
Date: Mon, 29 Jan 2018 17:43:15 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30
[[email protected] php-fpm.d]#
看下日志里有没有信息, 很明显地址 open_basedir restriction in effect 有限制
. File(/data/wwwroot/test.com/3.php) is not within the allowed path(s): (/data/wwwroot/wwtest.com:/tmp/)
很明显这俩个地址不同,所以就会报错,就会有问题
[[email protected] php-fpm.d]# cat /usr/local/php-fpm/var/log/php_errors.log
[29 Jan 2018 17:42:53 UTC] PHP Warning: Unknown: open_basedir restriction in effect. File(/data/wwwroot/test.com/3.php) is not within the allowed path(s): (/data/wwwroot/wwtest.com:/tmp/) in Unknown on line 0
[29 Jan 2018 17:42:53 UTC] PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0
[29 Jan 2018 17:43:15 UTC] PHP Warning: Unknown: open_basedir restriction in effect. File(/data/wwwroot/test.com/3.php) is not within the allowed path(s): (/data/wwwroot/wwtest.com:/tmp/) in Unknown on line 0
[29 Jan 2018 17:43:15 UTC] PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0
[[email protected] php-fpm.d]#
我们把它改正
[[email protected] 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
request_slowlog_timeout = 1
slowlog = /usr/local/php-fpm/var/log/www-slow.log
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
~
:wq
[[email protected] php-fpm.d]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[[email protected] php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php -I
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Mon, 29 Jan 2018 17:48:47 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30
[[email protected] php-fpm.d]#
现在可以了,这次就正常了,这就是openbasedir怎么去定义
12.24 php-fpm进程管理
[[email protected] php-fpm.d]# cat 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
request_slowlog_timeout = 1
slowlog = /usr/local/php-fpm/var/log/www-slow.log
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
[[email protected] php-fpm.d]#
pm = dynamic 表示以什么样的形式进程启动,用dynamic 动态,后面参数才会生效,
如果是静态,只有一行生效 pm.max_children = 50 其他后面的参数不会生效
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/235571/2126812