php.ini, php-fpm and www.conf configuration in PHP7
PHP7Configuration of php.ini, php-fpm and www.conf
php.ini is php running Core configuration file, the following are some common configurations
##extension_dir=""
expose_php = Off
display_errors = Off
log_errors = On
zend_extension=opcache.so extension=mysqli.so extension=pdo_mysql.so
date.timezone = PRC
opcache.enable=1
open_basedir = / usr/share/nginx/html;
php-fpm.conf is php-fpm The configuration file of the process service, the following are some common configurations
error_log = /usr/local/php/logs/php-fpm.log
include=/usr/local/php7/etc/php-fpm.d/*.conf
php-fpm.conf and main configuration information of www.conf
pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = notice
emergency_restart_threshold = 60
emergency_restart_interval = 60s
process_control_timeout = 0
daemonize = yes
listen = 127.0.0.1:9000
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www listen.group = www listen.mode = 0666
user = www group = www
php-fpm process pool optimization method
pm = dynamic
pm.max_children
pm.start_servers
pm.min_spare_servers
pm.max_spare_servers
● If dm is set to static, then only the parameter pm.max_children will take effect. The system will open the number of php-fpm processes set by the parameters. A php-fpm process will probably occupy 20m-40m of memory, so its numerical size setting should be set according to the size of your physical memory. You should also pay attention to other memory occupations, such as databases, system processes, etc., to determine The setting values of the above 4 parameters!
● If dm is set to dynamic, all four parameters will take effect. The system will start pm.start_servers php-fpm processes when php-fpm starts running, and then dynamically adjust the number of php-fpm processes between pm.min_spare_servers and pm.max_spare_servers according to the needs of the system. The parameter requires the value of pm.start_servers to be between pm.min_spare_servers and pm.max_spare_servers.
pm.max_requests = 1000
● Set the number of requests served before each child process is reborn.
● The maximum number of requests processed refers to a php -The fpm worker process will be terminated after processing a number of requests, and the master process will respawn a new one.
● The main purpose of this configuration is to avoid memory leaks caused by the php interpreter or third-party libraries referenced by the program.
This is very useful for third-party modules that may have memory leaks. If set to '0', requests will always be accepted. Equivalent to the PHP_FCGI_MAX_REQUESTS environment variable. Default value: 0.
pm.status_path = /status
● The URL of the FPM status page. If not set, the status page cannot be accessed. Default value: none. Munin monitoring will use
ping.path = /ping
● The ping URL of the FPM monitoring page. If not set, the ping page cannot be accessed. This page is used to externally detect whether the FPM is alive and can respond to requests . Please note that it must start with a slash (/).
ping.response = pong
● Used to define the return response of the ping request. The returned text/plain format text is HTTP 200. Default value: pong.
request_terminate_timeout = 0
● Set the timeout abort time for a single request. This option may not abort due to some special reasons for the 'max_execution_time' in the php.ini setting Useful for running scripts. Set to '0' for 'Off'. You can try changing this option when 502 errors occur frequently.
request_slowlog_timeout = 10s
● When a request exceeds the set timeout, the corresponding PHP call stack information will be completely written to the slow log. Settings '0' means 'Off'
slowlog = log/$pool.log.slow
● Slow request logging, used with request_slowlog_timeout
rlimit_files = 1024
● Set the rlimit limit of the file open descriptor. Default value: The system-defined value of the default open handle is 1024, which can be viewed using ulimit -n, ulimit -n 2048 modified.
rlimit_core = 0
● Set the maximum limit value of core rlimit. Available values: 'unlimited', 0 or positive integer. Default value: System-defined value.
chroot =
● Chroot directory at startup. The defined directory needs to be an absolute path. If not set, chroot will not be used.
chdir =
● Set the startup directory, which will be automatically Chdired to during startup. The defined directory needs to be an absolute path. Default value: current directory, or / directory (when chrooting)
catch_workers_output = yes
● Redirect stdout and stderr during the running process to the main error log file. If not set, stdout and stderr will be based on FastCGI The rules are redirected to /dev/null . Default value: empty.`
clear_env = no
● Clean up the environment
variables_order
The variables_order parameter is explained in detail in another articlehttps://www.php.cn/php-weizijiaocheng-429277.html
Common errors and solutions
The request timeout is not set
● If the value of request_terminate_timeout is set to 0 or too long, it may Causes the PHP script to continue executing. In this way, when all php-cgi processes are stuck in the file_get_contents() function, the Nginx PHP WebServer can no longer process new PHP requests, and Nginx will return "502 Bad Gateway" to the user. Setting the maximum execution time of a
PHP script is necessary, but it treats the symptoms rather than the root cause. For example, if it is changed to 30s, if file_get_contents() is slow to obtain web page content, this means that 150 php-cgi processes can only handle 5 requests per second, and it is also difficult for WebServer to avoid "502 Bad Gateway". The solution is to set request_terminate_timeout to 10s or a reasonable value, or add a timeout parameter to file_get_contents!
Improper configuration of the max_requests parameter
● Improper configuration of the max_requests parameter may cause intermittent 502 errors:
pm.max_requests = 1000
● Set the number of requests served before each child process is reborn. This is very useful for third-party modules that may have memory leaks. If set to '0', requests will always be accepted. Equivalent to the PHP_FCGI_MAX_REQUESTS environment variable. Default value : 0.
This configuration means that when the number of requests processed by a PHP-CGI process accumulates to 500, the process will be automatically restarted.
● But why do we need to restart the process?
● Generally in projects, we will use some third-party libraries of PHP to some extent. These third-party libraries often have memory leak problems. If the PHP-CGI process is not restarted regularly, it will inevitably cause memory usage. Growing. Therefore, PHP-FPM, as the manager of PHP-CGI, provides such a monitoring function to restart the PHP-CGI process that has requested a specified number of times to ensure that the memory usage does not increase.
php-fpm's slow log, debug and exception troubleshooting artifact
● request_slowlog_timeout sets a timeout parameter, slowlog sets the storage location of the slow log, tail -f / You can see the php process that executes too slowly in var/log/www.slow.log.
You can see the common problems of excessive network reading and slow Mysql query. If you troubleshoot the problem according to the prompt information, you will have a clear direction.
The above is the detailed content of php.ini, php-fpm and www.conf configuration in PHP7. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In php5, we can use the fsockopen() function to detect the TCP port. This function can be used to open a network connection and perform some network communication. But in php7, the fsockopen() function may encounter some problems, such as being unable to open the port, unable to connect to the server, etc. In order to solve this problem, we can use the socket_create() function and socket_connect() function to detect the TCP port.

How to install the mongo extension in php7.0: 1. Create the mongodb user group and user; 2. Download the mongodb source code package and place the source code package in the "/usr/local/src/" directory; 3. Enter "src/" directory; 4. Unzip the source code package; 5. Create the mongodb file directory; 6. Copy the files to the "mongodb/" directory; 7. Create the mongodb configuration file and modify the configuration.

To resolve the plugin not showing installed issue in PHP 7.0: Check the plugin configuration and enable the plugin. Restart PHP to apply configuration changes. Check the plugin file permissions to make sure they are correct. Install missing dependencies to ensure the plugin functions properly. If all other steps fail, rebuild PHP. Other possible causes include incompatible plugin versions, loading the wrong version, or PHP configuration issues.

Common solutions for PHP server environments include ensuring that the correct PHP version is installed and that relevant files have been copied to the module directory. Disable SELinux temporarily or permanently. Check and configure PHP.ini to ensure that necessary extensions have been added and set up correctly. Start or restart the PHP-FPM service. Check the DNS settings for resolution issues.

How to install and deploy php7.0: 1. Go to the PHP official website to download the installation version corresponding to the local system; 2. Extract the downloaded zip file to the specified directory; 3. Open the command line window and go to the "E:\php7" directory Just run the "php -v" command.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...

Compared with PHP7, PHP8 has some advantages and improvements in terms of performance, new features and syntax improvements, type system, error handling and extensions. However, choosing which version to use depends on your specific needs and project circumstances. Detailed introduction: 1. Performance improvement, PHP8 introduces the Just-in-Time (JIT) compiler, which can improve the execution speed of the code; 2. New features and syntax improvements, PHP8 supports the declaration of named parameters and optional parameters, making functions Calling is more flexible; anonymous classes, type declarations of properties, etc. are introduced.
