PHP-FPM Configuration

Source: Internet
Author: User
Tags fpm

First, the pool of PHP-FPM

The PHP-FPM configuration file php-fpm.conf can be set to multiple pool, where one pool resource is exhausted, causing other sites to be unable to access resources, reporting a 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 [Zlinux]listen =/tmp/zlinux.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.sockzlinux.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 zlinuxphp-fpm 2592 0.0 0.2 227180 4724?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2593 0.0 0.2 227180 4724?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2594 0.0 0.2 227180 4724?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2595 0.0 0.2 227180 4728?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2596 0.0 0.2 227180 4728?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2597 0.0 0.2 227180 4728?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2598 0.0 0.2 227180 4728?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2599 0.0 0.2 227180 4728? S 18:08 0:00 Php-fpm:pool zlinuxphp-FPM 2600 0.0 0.2 227180 4728?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2601 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2602 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2603 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2604 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2605 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2606 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2607 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2608 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2609 0.0 0.2 227180 4732?        S 18:08 0:00 php-fpm:pool zlinuxphp-fpm 2610 0.0 0.2 227180 4732? S 18:08 0:00 Php-fpm:pool zlinux
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 zlinux.confserver{   listen 80 default_server;#  有default_server标记的就是默认虚拟主机   server_name zlinuxtest.com;   index index.html index.htm index.php;   root /data/wwwroot/zlinux; location ~ \.php$        {            include fastcgi_params;            # 这里写对应php-fpm.conf内设置的sock            fastcgi_pass unix:/tmp/zlinux.sock;            fastcgi_index index.php;             fastcgi_param SCRIPT_FILENAME /data/wwwroot/zlinux$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

The above sets the pool separately, which is saved separately in the folder. You can also pool-fpm.conf add multiple pool directly in, and the site calls the corresponding row.

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 [zlinux]listen = /tmp/zlinux.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/zlinux-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/zlinux-slow.log[[email protected] vhost]# chmod 777 /usr/local/php-fpm/var/log/zlinux-slow.log[[email protected] vhost]# echo ‘<?php echo "slowlog test!"; sleep(2);echo "done"; ?>‘ > /data/wwwroot/zlinux/sleep.php[[email protected] php-fpm.d]# curl -x127.0.0.1:80 zlinux.com/sleep.phpslowlog test!done[[email protected] php-fpm.d]# [[email protected] php-fpm.d]# cat /usr/local/php-fpm/var/log/zlinux-slow.log     //查看蛮日志[19-Mar-2018 19:48:08]  [pool zlinux] pid 2354script_filename = /data/wwwroot/zlinux/sleep.php[0x00007f8f0c1802e8] sleep() /data/wwwroot/zlinux/sleep.php:3[19-Mar-2018 19:53:29]  [pool zlinux] pid 2356script_filename = /data/wwwroot/zlinux/sleep.php[0x00007f8f0c1802e8] sleep() /data/wwwroot/zlinux/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/zlinux.conf   //加入如下内容php_admin_value[open_basedir]=/data/wwwroot/zlinux:/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.

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.