94.PHP-FPM Configuration

Source: Internet
Author: User
Tags fpm

The pool of PHP-FPM

PHP-FPM configuration file php-fpm.conf can set multiple pool, in which one pool resource is exhausted, will cause other sites to not access resources, reported 502 error. It is necessary to separate the sites, using separate pool respectively.

1. Modify the configuration file
pear.conf  php-fpm.conf  php-fpm.conf.default  php.ini[[email protected] etc]# vim php-fpm.confinclude = etc/php-fpm.d/*.conf[global]#定义全局参数pid = /usr/local/php-fpm/var/run/php-fpm.piderror_log = /usr/local/php-fpm/var/log/php-fpm.log#添加上面这行,暂时注释掉下面的pool#[www]#listen = /tmp/php-fcgi.sock#监听地址,也可以写:listen = 127.0.0.1:9000,本地监听,也可以监听其他IP:port#此处格式会影响配置Nginx和PHP结合时Nginx寻址PHP的路径#listen.mode = 666#当监听的为socket文件时该部分才生效,用于指定.sock文件的权限#user = php-fpm#group = php-fpm#定义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. Create a profile directory and sub-configuration file
[[email protected] etc]# mkdir/usr/local/php-fpm/etc/php-fpm.d[[email protected] etc]# CD php-fpm.d[[ Email protected] php-fpm.d]# ls[[email protected] php-fpm.d]# vim www.conf//new configuration file write to the following [Www]listen =/ tmp/www.sock# listening address, can also write: listen = 127.0.0.1:9000, local monitoring, can also listen to other ip:port# here format will affect the configuration nginx and PHP when the Nginx address PHP path Listen.mode = 666# This section takes effect when listening to a socket file, specifying the permissions for the. sock file user = Php-fpmgroup = php-fpm# Defines the user of the PHP-FPM service pm = Dynamicpm.max_children = 50pm.start_servers = 20pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 500rlimit_files = 1024# The above section is process-related information [[email protected] php-fpm.d]# vim zlinu.conf//In creating another profile, write the following [Sdwaqw]listen =/tmp/sdwaqw.s ock# listening address, can also write: listen = 127.0.0.1:9000, local monitoring, can also listen to other ip:port# here format will affect the configuration nginx and PHP when the Nginx address php path Listen.mode = 666# This section takes effect when listening to a socket file, specifying the permissions for the. sock file. user = Php-fpmgroup = php-fpm# defines the PHP-FPM service for users pm = Dynamicpm.max_children = 50pm.start_servers = 20pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requeSTS = 500rlimit_files = 1024# The above part is process-related information 
3. Verify the configuration
[[email protected] php-fpm.d]#/usr/local/php-fpm/sbin/php-fpm-t[19-mar-2018 18:07:47] Notice:configuration File/usr/local/php-fpm/etc/php-fpm.conf test is successful[[email protected] php-fpm.d]#/etc/init.d/php-fpm Restartgracefully shutting down php-fpm. Donestarting php-fpm done[[email protected] php-fpm.d]# ls/tmp/|   grep sockmysql.sockwww.socksdwaqw.sock[[email protected] php-fpm.d]# PS aux |grep phproot 2570 0.0 0.2 227240        4992?        Ss 18:08 0:00 php-fpm:master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 2571 0.0 0.2 227180 4720?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2572 0.0 0.2 227180 4720?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2573 0.0 0.2 227180 4720?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2574 0.0 0.2 227180 4720?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2575 0.0 0.2 227180 4724? S 18:08 0:00 php-fpm:pool wwwphp-fpm 2576 0.0 0.2 227180 4724?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2577 0.0 0.2 227180 4724?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2578 0.0 0.2 227180 4724?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2579 0.0 0.2 227180 4724?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2580 0.0 0.2 227180 4724?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2581 0.0 0.2 227180 4724?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2582 0.0 0.2 227180 4724?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2583 0.0 0.2 227180 4724?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2584 0.0 0.2 227180 4724?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2585 0.0 0.2 227180 4728?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2586 0.0 0.2 227180 4728?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2587 0.0 0.2 227180 4728? S 18:08 0:00 php-fpm:pool wwwphp-fpm 2588 0.0 0.2 227180 4728?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2589 0.0 0.2 227180 4728?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2590 0.0 0.2 227180 4728?        S 18:08 0:00 php-fpm:pool wwwphp-fpm 2591 0.0 0.2 227180 4724?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2592 0.0 0.2 227180 4724?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2593 0.0 0.2 227180 4724?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2594 0.0 0.2 227180 4724?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2595 0.0 0.2 227180 4728?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2596 0.0 0.2 227180 4728?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2597 0.0 0.2 227180 4728?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2598 0.0 0.2 227180 4728?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2599 0.0 0.2 227180 4728? S 18:08 0:00 Php-fpm:pool sdwaqwphp-FPM 2600 0.0 0.2 227180 4728?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2601 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2602 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2603 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2604 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2605 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2606 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2607 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2608 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2609 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool sdwaqwphp-fpm 2610 0.0 0.2 227180 4732? S 18:08 0:00 Php-fpm:pool sdwaqw
4. Modify the virtual host configuration file to configure the pool for the site
[[email protected] php-fpm.d]# cd /usr/local/nginx/conf/vhost[[email protected] vhost]# vim sdwaqw.confserver{   listen 80 default_server;#  有default_server标记的就是默认虚拟主机   server_name sdwaqwtest.com;   index index.html index.htm index.php;   root /data/wwwroot/sdwaqw; location ~ \.php$        {            include fastcgi_params;            # 这里写对应php-fpm.conf内设置的sock            fastcgi_pass unix:/tmp/sdwaqw.sock;            fastcgi_index index.php;            fastcgi_param SCRIPT_FILENAME /data/wwwroot/sdwaqw$fastcgi_script_name;         }}[[email protected] vhost]# /usr/local/nginx/sbin/nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful以上为分别设置pool,单独保存在文件夹。也可以直接在pool-fpm.conf中添加多个pool,站点调用对应的就行。
Second, php-fpm slow execution log 1, edit the configuration file
[[email protected] vhost]# vim /usr/local/php-fpm/etc/php-fpm.d/zlinu.conf[sdwaqw]listen = /tmp/sdwaqw.sock#监听地址,也可以写:listen = 127.0.0.1:9000,本地监听,也可以监听其他IP:port#此处格式会影响配置Nginx和PHP结合时Nginx寻址PHP的路径listen.mode = 666#当监听的为socket文件时该部分才生效,用于指定.sock文件的权限user = php-fpmgroup = php-fpm#定义php-fpm服务的用户pm = dynamicpm.max_children = 50pm.start_servers = 20pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 500rlimit_files = 1024#以上部分为进程相关信息request_slowlog_timeout = 1#当请求超过1秒开始记录日志slowlog = /usr/local/php-fpm/var/log/sdwaqw-slow.log#日志存放地址[[email protected] vhost]# /usr/local/php-fpm/sbin/php-fpm -t[19-Mar-2018 18:30:23] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful[[email protected] vhost]# /etc/init.d/php-fpm restartGracefully shutting down php-fpm . doneStarting php-fpm  done
2, Test slow log
[[email protected] vhost]# touch /usr/local/php-fpm/var/log/sdwaqw-slow.log[[email protected] vhost]# chmod 777 /usr/local/php-fpm/var/log/sdwaqw-slow.log[[email protected] vhost]# echo ‘<?php echo "slowlog test!"; sleep(2);echo "done"; ?>‘ > /data/wwwroot/sdwaqw/sleep.php[[email protected] php-fpm.d]# curl -x127.0.0.1:80 sdwaqw.com/sleep.phpslowlog test!done[[email protected] php-fpm.d]#[[email protected] php-fpm.d]# cat /usr/local/php-fpm/var/log/sdwaqw-slow.log     //查看蛮日志[19-Mar-2018 19:48:08]  [pool sdwaqw] pid 2354script_filename = /data/wwwroot/sdwaqw/sleep.php[0x00007f8f0c1802e8] sleep() /data/wwwroot/sdwaqw/sleep.php:3[19-Mar-2018 19:53:29]  [pool sdwaqw] pid 2356script_filename = /data/wwwroot/sdwaqw/sleep.php[0x00007f8f0c1802e8] sleep() /data/wwwroot/sdwaqw/sleep.php:3
Third, PHP-FPHP-FPM definition Open_basedir

When a server runs multiple sites, use Openbasedir to limit the range of directories on the servers that each site can access. In the PHP-FPM service, open Basedir can be set for each pool.
[Email protected] php-fpm.d]# vim/usr/local/php-fpm/etc/php-fpm.d/sdwaqw.conf//Add the following:
php_admin_value[open_basedir]=/data/wwwroot/sdwaqw:/tmp/

Iv. PHP-FPM Process Management

PM = dynamic
Dynamic process management can also be static
; The following configuration will only take effect if this is set to dynamic
Pm.max_children = 50
Maximum number of sub-processes, PS aux can be viewed
Pm.start_servers = 20
: The number of processes that will start when the service is started
Pm.min_spare_servers = 5
To define the idle time period, the minimum number of child processes, if this value is reached, the PHP-FPM
The service automatically derives new child processes.
Pm.max_spare_servers = 35
Define the maximum value of the child process during the idle period, and start cleaning up the idle child process if it is above this value.
Pm.max_requests = 500
; Defines the maximum number of requests a child process can handle, meaning that a php-fpm child process is able to handle the request at most, and when that value is reached, he automatically exits.

94.PHP-FPM Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.