Home Backend Development PHP7 php.ini, php-fpm and www.conf configuration in PHP7

php.ini, php-fpm and www.conf configuration in PHP7

Aug 23, 2019 pm 02:07 PM
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=""

● Set the PHP extension library path

expose_php = Off

● Avoid exposing PHP information in http headers

display_errors = Off

● Avoid exposing PHP errors when calling mysql Information

log_errors = On

● Turn on the PHP error log after turning off display_errors (the path is configured in php-fpm.conf)

zend_extension=opcache.so extension=mysqli.so extension=pdo_mysql.so

● Set up PHP’s opcache and mysql dynamic libraries

date.timezone = PRC

● Set the time zone of PHP

opcache.enable=1

● Turn on opcache

open_basedir = / usr/share/nginx/html;

● Set the directory that PHP scripts are allowed to access (needs to be configured according to the actual situation)

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

● Settings The path of the error log

include=/usr/local/php7/etc/php-fpm.d/*.conf

●Introduced into the www.conf file Configuration (set by default)

php-fpm.conf and main configuration information of www.conf

pid = run/php-fpm.pid

● pid setting, the default is var/run/php-fpm.pid in the installation directory. It is recommended to enable

error_log = log/php-fpm.log

● Error log, var/log/php-fpm.log in the installation directory by default

log_level = notice

● Error level . Available levels are: alert (must be handled immediately), error (error situation), warning (warning situation), notice (general important information), debug (debugging information). Default: notice.

emergency_restart_threshold = 60

emergency_restart_interval = 60s

● Indicates that the number of php-cgi processes that have SIGSEGV or SIGBUS errors within the value set by emergency_restart_interval exceeds emergency_restart_threshold , php-fpm will restart gracefully. These two options generally remain at their default values.

process_control_timeout = 0

● Set the timeout for the child process to accept the main process multiplexing signal. Available units: s (seconds), m (minutes), h ( hours), or d (days) Default unit: s (seconds). Default value: 0.

daemonize = yes

● Execute fpm in the background, the default value is yes, you can change it to no for debugging. In FPM, it is possible to run multiple process pools with different settings. These settings can be set individually for each process pool.

listen = 127.0.0.1:9000

● The listening port is the address processed by PHP in nginx. Generally, the default value is sufficient. Available formats are: 'ip:port', 'port', '/path/to/unix/socket'. Each process pool needs to be set.

listen.backlog = -1

● Backlog number, -1 means unlimited, determined by the operating system, just comment out this line.

listen.allowed_clients = 127.0.0.1

● Allow access to the IP of the FastCGI process. Set any to not restrict the IP. If you want to set up nginx on other hosts, you can also access it. For this FPM process, the listen location must be set to a local IP that can be accessed. The default value is any. Each address is separated by a comma. If not set or empty, any server requesting a connection is allowed

listen.owner = www listen.group = www listen.mode = 0666

● Unix socket setting options, if you use tcp to access, just comment here.

user = www group = www

● Account and group to start the process

php-fpm process pool optimization method

pm = dynamic

● For dedicated servers, pm can be set to static.

How to control the child process, the options are static and dynamic. If static is selected, a fixed number of child processes is specified by pm.max_children. If dynamic is selected, it is determined by the following parameters:

pm.max_children

● The number of php-fpm processes opened in static mode is limited in dynamic mode The maximum number of processes for php-fpm (note here that the value of pm.max_spare_servers can only be less than or equal to pm.max_children)

pm.start_servers

● In dynamic mode Number of starting php-fpm processes.

pm.min_spare_servers

● Ensure the minimum number of idle processes. If the idle processes are less than this value, create a new child process

pm.max_spare_servers

● Ensure the maximum number of idle processes. If the idle processes are greater than this value, they will be cleaned up

● 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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the problem when php7 detects that the tcp port is not working How to solve the problem when php7 detects that the tcp port is not working Mar 22, 2023 am 09:30 AM

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 mongo extension in php7.0 How to install mongo extension in php7.0 Nov 21, 2022 am 10:25 AM

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.

What should I do if the plug-in is installed in php7.0 but it still shows that it is not installed? What should I do if the plug-in is installed in php7.0 but it still shows that it is not installed? Apr 02, 2024 pm 07:39 PM

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.

PHP Server Environment FAQ Guide: Quickly Solve Common Problems PHP Server Environment FAQ Guide: Quickly Solve Common Problems Apr 09, 2024 pm 01:33 PM

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 How to install and deploy php7.0 Nov 30, 2022 am 09:56 AM

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 permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

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...

Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Apr 01, 2025 pm 03:06 PM

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

Which one is better, php8 or php7? Which one is better, php8 or php7? Nov 16, 2023 pm 03:09 PM

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.

See all articles