[LNMP]php-fpm相关配置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LNMP]php-fpm相关配置相关的知识,希望对你有一定的参考价值。
php-fpm pool
方式一
1、编辑php-fpm配置文件
[[email protected] ~]# vi /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.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 #####添加以下内容##### [test.com] listen = /tmp/test.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
2、检查与重载
[[email protected] ~]# /usr/local/php-fpm/sbin/php-fpm -t [17-Aug-2017 21:15:03] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful [[email protected] ~]# /etc/init.d/php-fpm reload Reload service php-fpm done [[email protected] ~]# ps aux |grep php-fpm root 88331 0.0 0.1 226756 4976 ? Ss 21:15 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 88332 0.0 0.1 226696 4712 ? S 21:15 0:00 php-fpm: pool www php-fpm 88333 0.0 0.1 226696 4712 ? S 21:15 0:00 php-fpm: pool www php-fpm 88334 0.0 0.1 226696 4712 ? S 21:15 0:00 php-fpm: pool www php-fpm 88335 0.0 0.1 226696 4712 ? S 21:15 0:00 php-fpm: pool www php-fpm 88336 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool www php-fpm 88337 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool www php-fpm 88338 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool www php-fpm 88339 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool www php-fpm 88340 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool www php-fpm 88341 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool www php-fpm 88342 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool www php-fpm 88343 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88344 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88345 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88346 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88347 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88348 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88349 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88350 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88351 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88352 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88353 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88354 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88355 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88356 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88357 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88358 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88359 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88360 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88361 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88362 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88363 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88364 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88365 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88366 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88367 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88368 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88369 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88370 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test.com php-fpm 88371 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test.com root 88492 0.0 0.0 112652 968 pts/0 S+ 21:16 0:00 grep --color=auto php-fpm
3、编辑网站配置文件
[[email protected] ~]# vi /usr/local/nginx/conf/vhost/default.conf server { listen 80 default_server; server_name aaa.com; index index.html index.htm index.php; root /data/wwwroot/default; access_log /tmp/default.log juispan; location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/tmp/test.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name; } }
方式二
1、编辑php-fpm配置文件
[[email protected] ~]# vi /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
2、编辑网站配置文件
[[email protected] ~]# mkdir /usr/local/php-fpm/etc/php-fpm.d [[email protected] ~]# vi /usr/local/php-fpm/etc/php-fpm.d/test.conf [test] listen = /tmp/test.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] ~]# vi /usr/local/php-fpm/etc/php-fpm.d/abc.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
3、检查与重载
[[email protected] ~]# /usr/local/php-fpm/sbin/php-fpm -t [17-Aug-2017 21:15:03] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful [[email protected] ~]# /etc/init.d/php-fpm reload Reload service php-fpm done
4、检查效果
[[email protected] ~]# ps aux |grep php-fpm root 91955 0.1 0.1 226784 4980 ? Ss 21:50 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 91956 0.0 0.1 226724 4728 ? S 21:50 0:00 php-fpm: pool www php-fpm 91957 0.0 0.1 226724 4728 ? S 21:50 0:00 php-fpm: pool www php-fpm 91958 0.0 0.1 226724 4728 ? S 21:50 0:00 php-fpm: pool www php-fpm 91959 0.0 0.1 226724 4728 ? S 21:50 0:00 php-fpm: pool www php-fpm 91960 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool www php-fpm 91961 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool www php-fpm 91962 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool www php-fpm 91963 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool www php-fpm 91964 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool www php-fpm 91965 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool www php-fpm 91966 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91967 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91968 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91969 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91970 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91971 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91972 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91973 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91974 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91975 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91976 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool test php-fpm 91977 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool test php-fpm 91978 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool test php-fpm 91979 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool test php-fpm 91980 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool test php-fpm 91981 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool test php-fpm 91982 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test php-fpm 91983 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test php-fpm 91984 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test php-fpm 91985 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test php-fpm 91986 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test php-fpm 91987 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test php-fpm 91988 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test php-fpm 91989 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test php-fpm 91990 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test php-fpm 91991 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test php-fpm 91992 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test php-fpm 91993 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test php-fpm 91994 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test php-fpm 91995 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test root 92012 0.0 0.0 112652 968 pts/0 S+ 21:50 0:00 grep --color=auto php-fpm
慢执行日志
1、编辑网站配置文件
[[email protected] ~]# vi /usr/local/php-fpm/etc/php-fpm.d/test.conf [test] listen = /tmp/test.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 request_slowlog_timeout = 2 ##超过2秒记录日志 slowlog = /usr/local/php-fpm/var/log/test_slow.log
2、检查与重载
[[email protected] ~]# /usr/local/php-fpm/sbin/php-fpm -t [17-Aug-2017 21:56:07] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful [[email protected] ~]# /etc/init.d/php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done
3、检查效果
[[email protected] ~]# cat /usr/local/php-fpm/var/log/test_slow.log [17-Aug-2017 22:01:42] [pool test] pid 92722 script_filename = /data/wwwroot/default/1.php [0x00007fc823e8f2d0] sleep() /data/wwwroot/default/1.php:3
open_basedir
1、配置网站配置文件
[[email protected] ~]# echo "php_admin_value[open_basedir]=/data/wwwroot/default:/tmp/" >> /usr/local/php-fpm/etc/php-fpm.d/test.conf ##限制default目录下不可以访问其他站点资源
2、编辑php.ini文件
[[email protected] ~]# vi /usr/local/php-fpm/etc/php.ini errot_log = /usr/local/php-fpm/var/log/php_error.log
3、检查与重载
[[email protected] ~]# /usr/local/php-fpm/sbin/php-fpm -t [17-Aug-2017 21:15:03] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful [[email protected] ~]# /etc/init.d/php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done
3、测试效果
[[email protected] ~]# touch /usr/local/php-fpm/var/log/php_error.log [[email protected] ~]# chmod 777 /usr/local/php-fpm/var/log/php_error.log [[email protected] ~]# curl -x127.0.0.1:80 abc.com/2.php File not found. [[email protected] ~]# ls /data/wwwroot/abc.com/ 2.php
进程管理
▎配置文件参数详解:
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的子进程最多可以处理这么多请求,当达到这个数值时,它会自动退出。
本文出自 “Gorilla City” 博客,请务必保留此出处http://juispan.blog.51cto.com/943137/1957195
以上是关于[LNMP]php-fpm相关配置的主要内容,如果未能解决你的问题,请参考以下文章
lnmp配置(linux(centos7).ngnix.mariadb.php(php-fpm,phpmyadmin))