12.21 php-fpm的pool
12.22 php-fpm慢執行日誌
12.23 open_basedir
12.24 php-fpm進程管理javascript
[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
[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
[root@yong-01 ~]# ps aux |grep php-fpm root 1489 0.0 0.2 227204 4952 ? Ss 21:19 0:00 php-fpm: master process (/usr/localphp-fpm/etc/php-fpm.conf) php-fpm 1490 0.0 0.2 227204 4708 ? S 21:19 0:00 php-fpm: pool www php-fpm 1491 0.0 0.2 227204 4708 ? S 21:19 0:00 php-fpm: pool www php-fpm 1492 0.0 0.2 227204 4708 ? S 21:19 0:00 php-fpm: pool www
[root@yong-01 ~]# cd /usr/local/php-fpm/etc/ [root@yong-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 = 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
[root@yong-01 etc]# /usr/local/php-fpm/sbin/php-fpm -t [13-Jun-2018 21:34:08] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@yong-01 etc]# /etc/init.d/php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done
[root@yong-01 etc]# cd /usr/local/nginx/conf/vhost/ [root@yong-01 vhost]# ls aaa.com.conf load.conf proxy.conf ssl.conf test.com.conf
[root@yong-01 vhost]# vim test.com.conf server { listen 80; server_name test.com test1.com test2.com; index index.html index.htm index.php; root /data/wwwroot/test.com; if ($host != 'test.com' ) { rewrite ^/(.*)$ http://test.com/$1 permanent; } #location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ #{ # expires 7d; # access_log off; #} location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$ { expires 7d; valid_referers none blocked server_names *.test.com ; if ($invalid_referer) { return 403; } access_log off; } location ~ .*\.(js|css)$ { expires 12h; access_log off; } location /admin/ { allow 192.168.180.134; allow 127.0.0.1; deny all; } location ~ .*(upload|image)/.*\.php$ { deny all; } if ($http_user_agent ~* 'Spider/3.0|YoudaoBot|Tomato') { return 403; } location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/tmp/php-fcgi.sock; #fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name; } access_log /tmp/test.com.log combined_realip; }
[root@yong-01 vhost]# vim 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/yueyong.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name; }
[root@yong-01 vhost]# ls aaa.com.conf load.conf proxy.conf ssl.conf test.com.conf [root@yong-01 vhost]# tail /usr/local/nginx/conf/nginx.conf tcp_nodelay on; gzip on; gzip_min_length 1k; gzip_buffers 4 8k; gzip_comp_level 5; gzip_http_version 1.1; gzip_types text/plain application/x-javascript text/css text/htm application/xml; include vhost/*.conf; }
[root@yong-01 conf]# cat /usr/local/php-fpm/etc/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 = 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 [yueyong] listen = /tmp/yueyong.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
最終以下php
[root@yong-01 conf]# vim /usr/local/php-fpm/etc/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@yong-01 etc]# mkdir php-fpm.d [root@yong-01 etc]# ls pear.conf php-fpm.conf php-fpm.conf.default php-fpm.d php.ini
[root@yong-01 etc]# cd php-fpm.d/ [root@yong-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@yong-01 php-fpm.d]# vim yueyong.conf [yueyong.com] listen = /tmp/yueyong.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
[root@yong-01 php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t [13-Jun-2018 22:05:59] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@yong-01 php-fpm.d]# /etc/init.d/php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done [root@yong-01 php-fpm.d]# ps aux |grep php-fpm root 1987 0.0 0.2 227292 4988 ? Ss 22:06 0:00 php-fpm: master process (/usr/localphp-fpm/etc/php-fpm.conf) php-fpm 1988 0.0 0.2 227232 4724 ? S 22:06 0:00 php-fpm: pool www php-fpm 1989 0.0 0.2 227232 4724 ? S 22:06 0:00 php-fpm: pool www php-fpm 1990 0.0 0.2 227232 4724 ? S 22:06 0:00 php-fpm: pool www php-fpm 1991 0.0 0.2 227232 4724 ? S 22:06 0:00 php-fpm: pool www php-fpm 1992 0.0 0.2 227232 4728 ? S 22:06 0:00 php-fpm: pool www php-fpm 1993 0.0 0.2 227232 4728 ? S 22:06 0:00 php-fpm: pool www php-fpm 1994 0.0 0.2 227232 4728 ? S 22:06 0:00 php-fpm: pool www php-fpm 1995 0.0 0.2 227232 4728 ? S 22:06 0:00 php-fpm: pool www php-fpm 1996 0.0 0.2 227232 4728 ? S 22:06 0:00 php-fpm: pool www php-fpm 1997 0.0 0.2 227232 4728 ? S 22:06 0:00 php-fpm: pool www php-fpm 1998 0.0 0.2 227232 4728 ? S 22:06 0:00 php-fpm: pool www php-fpm 1999 0.0 0.2 227232 4728 ? S 22:06 0:00 php-fpm: pool www php-fpm 2000 0.0 0.2 227232 4728 ? S 22:06 0:00 php-fpm: pool www php-fpm 2001 0.0 0.2 227232 4728 ? S 22:06 0:00 php-fpm: pool www php-fpm 2002 0.0 0.2 227232 4732 ? S 22:06 0:00 php-fpm: pool www php-fpm 2003 0.0 0.2 227232 4732 ? S 22:06 0:00 php-fpm: pool www php-fpm 2004 0.0 0.2 227232 4732 ? S 22:06 0:00 php-fpm: pool www php-fpm 2005 0.0 0.2 227232 4732 ? S 22:06 0:00 php-fpm: pool www php-fpm 2006 0.0 0.2 227232 4732 ? S 22:06 0:00 php-fpm: pool www php-fpm 2007 0.0 0.2 227232 4732 ? S 22:06 0:00 php-fpm: pool www php-fpm 2008 0.0 0.2 227232 4728 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2009 0.0 0.2 227232 4728 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2010 0.0 0.2 227232 4728 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2011 0.0 0.2 227232 4728 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2012 0.0 0.2 227232 4732 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2013 0.0 0.2 227232 4732 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2014 0.0 0.2 227232 4732 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2015 0.0 0.2 227232 4732 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2016 0.0 0.2 227232 4732 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2017 0.0 0.2 227232 4732 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2018 0.0 0.2 227232 4736 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2019 0.0 0.2 227232 4736 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2020 0.0 0.2 227232 4736 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2021 0.0 0.2 227232 4736 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2022 0.0 0.2 227232 4736 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2023 0.0 0.2 227232 4736 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2024 0.0 0.2 227232 4736 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2025 0.0 0.2 227232 4736 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2026 0.0 0.2 227232 4736 ? S 22:06 0:00 php-fpm: pool yueyong.com php-fpm 2027 0.0 0.2 227232 4736 ? S 22:06 0:00 php-fpm: pool yueyong.com root 2029 0.0 0.0 112676 980 pts/0 R+ 22:06 0:00 grep --color=auto php-fpm
request_slowlog_timeout = 1 slowlog = /usr/local/php-fpm/var/log/www-slow.log
<?php echo 「test slow log」; sleep(2);echo 「done」; ?>
request_slowlog_timeout = 1 //超過一秒鐘就要記錄日誌 slowlog = /usr/local/php-fpm/var/log/www-slow.log //日誌放到該路徑下
最終以下css
[root@yong-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 request_slowlog_timeout = 1 slowlog = /usr/local/php-fpm/var/log/www-slow.log
[root@yong-01 php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t [13-Jun-2018 22:19:19] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful [root@yong-01 php-fpm.d]# /etc/init.d/php-fpm reload Reload service php-fpm done
[root@yong-01 php-fpm.d]# ls /usr/local/php-fpm/var/log/ php-fpm.log www-slow.log [root@yong-01 php-fpm.d]# cat /usr/local/php-fpm/var/log/www-slow.log
[root@yong-01 php-fpm.d]# vim /data/wwwroot/test.com/sleep.php <?php echo 「test slow log」; sleep(2);echo 「done」; ?>
[root@yong-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php [root@yong-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php -I HTTP/1.1 500 Internal Server Error Server: nginx/1.4.7 Date: Wed, 13 Jun 2018 14:22:56 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Powered-By: PHP/5.6.30
[root@yong-01 php-fpm.d]# vim /usr/local/php-fpm/etc/php.ini 搜索 /display ,找到display_errors 將display_errors = Off 改成display_errors = On
[root@yong-01 php-fpm.d]# /etc/init.d/php-fpm reload Reload service php-fpm done
[root@yong-01 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 />
[root@hf-01 php-fpm.d]# vim /data/wwwroot/test.com/sleep.php <?php echo "test slow log"; sleep(2); echo "done"; ?> [root@yong-01 php-fpm.d]# /etc/init.d/php-fpm reload Reload service php-fpm done
[root@yong-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php test slow logdone
[root@yong-01 php-fpm.d]# cat /usr/local/php-fpm/var/log/www-slow.log [13-Jun-2018 22:31:01] [pool www] pid 2362 script_filename = /data/wwwroot/test.com/sleep.php //提示:是哪一個腳本慢 [0x00007fa3e9694270] sleep() /data/wwwroot/test.com/sleep.php:3 //提示:是腳本的第三慢 [13-Jun-2018 22:32:24] [pool www] pid 2364 script_filename = /data/wwwroot/test.com/sleep.php [0x00007fa3e9694528] sleep() /data/wwwroot/test.com/sleep.php:3
[root@yong-01 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/aming.com:/tmp/
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
- 若是路徑出錯,就會沒法正常訪問,致使404頁面 curl直接連會提示「No input file specified.」
[root@yong-01 php-fpm.d]# vim /usr/local/php-fpm/etc/php-fpm.d/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/
[root@yong-01 php-fpm.d]# /etc/init.d/php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done
[root@yong-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php -I HTTP/1.1 200 OK Server: nginx/1.4.7 Date: Wed, 13 Jun 2018 14:48:59 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Powered-By: PHP/5.6.30
[root@yong-01 php-fpm.d]# vim /usr/local/php-fpm/etc/php.ini 搜索 /display_errors 將display_errors = Off 搜索 /error_log,添加error_log error_log = /usr/local/php-fpm/var/log/php_errors.log //這一段定義錯誤日誌路徑 搜索error_reporting 註釋掉自帶的error_reporting ;error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT error_reporting = E_ALL //定義錯誤日誌的級別全部
[root@yong-01 php-fpm.d]# ls /usr/local/php-fpm/var/log/ php-fpm.log www-slow.log
[root@yong-01 php-fpm.d]# touch /usr/local/php-fpm/var/log/php_errors.log [root@yong-01 php-fpm.d]# chmod 777 /usr/local/php-fpm/var/log/php_errors.log
[root@yong-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php -I HTTP/1.1 404 Not Found Server: nginx/1.4.7 Date: Wed, 13 Jun 2018 15:00:11 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Powered-By: PHP/5.6.30 [root@yong-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php No input file specified.
[root@yong-01 php-fpm.d]# cat /usr/local/php-fpm/var/log/php_errors.log [13-Jun-2018 14:59:36 UTC] PHP Deprecated: Comments starting with '#' are deprecated in Unknown on line 1 in Unknown on line 0 [13-Jun-2018 15:00:11 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/test22.com:/tmp/) in Unknown on line 0 [13-Jun-2018 15:00:11 UTC] PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0 [13-Jun-2018 15:00:27 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/test22.com:/tmp/) in Unknown on line 0 [13-Jun-2018 15:00:27 UTC] PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0
[root@yong-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php -I HTTP/1.1 200 OK Server: nginx/1.4.7 Date: Wed, 13 Jun 2018 15:02:20 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Powered-By: PHP/5.6.30
[root@yong-01 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/