PHP-FPM pool, slow php logging, Open_basedir, PHP-FPM process Management

Source: Internet
Author: User
Tags fpm

1, php-fpm Poo Pond:
Purpose: Can make different Web sites, for different PHP parsing, can be different sites to separate the parsing area.
Editor:vim/usr/local/php5-fpm/etc/php-fpm.conf
Join:

[Test]
Listen =/tmp/php-test.sock
Listen.mode = 666
user = php-fpm
Group = php-fpm
pm = Dynamic
Pm.max_children =
pm.start_servers =
pm.min_spare_servers = 5
pm.max_spare_servers =
pm.max_requests =
rlimit_files = 1024x768
grammar checker:/usr/local/php5-fpm/sbin/php-fpm-t
Reload php-fpm:/etc/init.d/php-fpm Reload
view:ps-aux | grep php-fpm


View:

In the preparation of Nginx virtual host can be corresponding to change, such as in the server to add the following code:

Location ~ \.php$
{
#把php整合
Include Fastcgi_params;
Fastcgi_pass Unix:/tmp/php-test.sock;
#fastcgi_pass 127.0.0.1:8080;
Fastcgi_index index.php;
Fastcgi_param Script_filename/var/www/test.com$fastcgi_script_name;
}

Once the Nginx is reloaded, the parsing will be separated.

This way, you can make the site of different PHP parsing, but can also be optimized, modified as follows:
Modified:/usr/local/php5-fpm/etc/php-fpm.conf
Change to:

[Global]
PID =/usr/local/php5-fpm/var/run/php-fpm.pid
Error_log =/usr/local/php5-fpm/var/log/php-fpm.log
include=/usr/local/php5-fpm/etc/vconf/*
Create a vconf directory under /usr/local/php5-fpm/etc/ :mkdir/usr/local/php5-fpm/etc/vconf/
Create a configuration file for the corresponding virtual machine:vim/usr/local/php5-fpm/etc/vconf/test.conf and add the relevant code:

[name_xxxx] #对应的解析池名可以自己随便取
Listen =/tmp/vconf.sock
listen.mode=666
user = php-fpm
Group = php-fpm
pm = Dynamic
Pm.max_children =
pm.start_servers =
pm.min_spare_servers = 5
pm.max_spare_servers =
pm.max_requests =
rlimit_files = 1024x768
check Syntax:/usr/local/php5-fpm/sbin/php-fpm-t
then reload:/etc/init.d/php-fpm Reload


View:

Later, you can set up under the vconf, different virtual machine PHP parsing pool.

2. Slow log recording of PHP

Purpose: To find out why the website is slow
To edit a configuration file for a slow host:vim/usr/local/php5-fpm/etc/vconf/test.conf
Additional:

Request_slowlog_timeout = 1 #这里默认一般设置为2秒
Slowlog =/usr/local/php5-fpm/var/log/test-slow.log
Check syntax:/usr/local/php5-fpm/sbin/php-fpm-t
Then reload:/etc/init.d/php-fpm Reload

Write a PHP file and add the following code to test it:

<?php
echo "Vconf_test. COM _php; Test slow Log "; sleep (2);
?>

Then go to:

To this slow-logging configuration is complete.

3. Open_basedir Directory Access control
Purpose: Set directory permission access control
Editor:vim/usr/local/php5-fpm/etc/vconf/test.conf
Append:php_admin_value[open_basedir]=/var/www/test.com:/tmp/ #这里表示, permission to access only/var/www/test.com and/tmp/directories
(This can be understood, that is, when the PHP module is parsed, it can only run in these 2 directories)
                 

Check syntax:/usr/local/php5-fpm/sbin/php-fpm-t
Then reload:/etc/init.d/php-fpm Reload
If you change the root directory of/usr/local/nginx/conf/vhost/test.com.conf to the/var/www/222 directory, try to access:

Then, we test:

Summarize:
The configuration file inside the PHP parsing module

(/usr/local/php5-fpm/etc/vconf/test.conf ) file parsing directory (php_admin_value[open_basedir]=/var/www/ test.com:/tmp/ ) is restricted, and
Nginx configuration file
(/usr/local/nginx/conf/vhost/test.com.conf) in the PHP integration module (fastcgi_param script_filename /var/www /test.com$fastcgi _script_name; )
PHP files are stored in the same path. If not, when you access the PHP file, it will display:no input file specified. (That is, the specified file cannot be found)

If the Nginx configuration file
(/usr/local/nginx/conf/vhost/test.com.conf) in the root/var/www/test.com; and Fastcgi_param script_filename /var/www/test.com$fastcgi _script_name;
The path is different, then when you access the PHP file, it displays file not found(that is, no files found).  

4. PHP-FPM Process Management
Edit:vim/usr/local/php5-fpm/etc/vconf/test.conf file, the preparation, according to the actual situation of the machine to be prepared.

[vconf]
Listen =/tmp/vconf.sock
listen.mode=666
Span style= "COLOR: #ff0000" > user = php-fpm
group = PHP-FPM
pm = dynamic
;p m =static
Pm.max_children = 50
pm.start_servers =
pm.min_spare_servers = 5
pm.max_ Spare_servers =
pm.max_requests = $
rlimit_files = 1024x768

Request_slowlog_timeout = 1
Slowlog =/usr/local/php5-fpm/var/log/test-slow.log

php_admin_value[open_basedir]=/var/www/test.com/:/tmp/


To this LNMP related learning closed.

PHP-FPM pool, slow php logging, Open_basedir, PHP-FPM process Management

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.