Php-fpm.conf configuration instructions (focus on modifying and optimizing), phpfpm. conf
<? Xml version = "1.0"?> <Configuration> All relative paths in this config are relative to php's install prefix <section name = "global_options"> Pid file <value name = "pid_file">/usr/local/ php/logs/php-fpm.pid </value> Error log file <value name = "error_log">/usr/local/php/logs/php-fpm.log </value> Log level <value name = "log_level"> notice </value> When this amount of php processes exited with SIGSEGV or SIGBUS... <value name = "emergency_r Estart_threshold "> 10 </value>... in a less than this interval of time, a graceful restart will be initiated. useful to work around und accidental curruptions in accelerator's shared memory. <value name = "emergency_restart_interval"> 1 m </value> Time limit on waiting child's reaction on signals from master <value name = "process_control_timeout"> 5 s </value> set to 'no' to debug fpm <value name = "daemonize"> yes </valu E> </section> <workers> <section name = "pool"> Name of pool. used in logs and stats. <value name = "name"> default </value> Address to accept fastcgi requests on. valid syntax is 'IP. ad. re. ss: port 'or just 'Port' or'/path/to/unix/socket '<value name = "listen_address"> 127.0.0.1: 9000 </value> <! -- Default ip address and port --> <value name = "listen_options"> Set listen (2) backlog <value name = "backlog">-1 </value> Set permissions for unix socket, if one used. in Linux read/write permissions must be set in order to allow connections from web server. extends BSD-derrived systems allow connections regardless of permissions. <value name = "owner"> </value> <! -Username with the same name as nginx ---> <value name = "group"> </value> <! -Working Group with the same name as nginx ---> <value name = "mode"> 0666 </value> Additional php. ini defines, specific to this pool of workers. <value name = "php_defines"> <! -- <Value name = "sendmail_path">/usr/sbin/sendmail-t-I </value> --> <! -- <Value name = "display_errors"> 0 </value> # error 0 is not displayed, and 1 is displayed --> </value> Unix user of processes <! -- <Value name = "user"> nobody </value> --> Unix group of processes <! -- <Value name = "group"> nobody </value> --> Process manager settings <value name = "pm"> Sets style of controling worker process count. valid values are 'static 'and 'apache-like' <value name = "style"> static </value> Sets the limit on the number of simultaneous requests that will be served. equivalent to Apache MaxClients directive. equivalent to PHP_FCGI_CHILDREN environment in original php. fcgiUsed with any pm_s Tyle. <value name = "max_children"> 5 </value> <! -- The default number of fastcgi processes is 5. If the memory is smaller than 2 GB, 20 processes can be set. If the memory is larger than 4 GB, 200 processes can be set, note that this is not the only one --> Settings group for 'apache-like 'pm style <value name = "apache_like"> Sets the number of server processes created on startup. used only when 'apache-like 'pm_style is selected <value name = "StartServers"> 20 </value> Sets the desired minimum number of idle server processes. used only when 'apache-like 'pm_style is selected <value name = "MinSpareServers"> 5 </Value> Sets the desired maximum number of idle server processes. used only when 'apache-like 'pm_style is selected <value name = "MaxSpareServers"> 35 </value> The timeout (in seconds) for serving a single request after which the worker process will be terminatedshoshould be used when 'max _ execution_time 'ini option does not stop script execution for some reason '0s' means 'off' <value name = "r Equest_terminate_timeout "> 0 s </value> <! -- The default value of The fastcgi script is 0 seconds. --> The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow. log file '0s' means 'off' <value name = "request_slowlog_timeout"> 0 s </value> The log file for slow requests <value name = "slowlog"> logs/slow. log </value> Set open file desc rlimit <value name = "rlimit_files"> 1024 </value> <! -- The maximum number of opened file descriptors can be associated with the number of opened files in the Linux kernel. For example, run the following command: ulimit-Hsn 65536 --> Set max core size rlimit <value name = "rlimit_core"> 0 </value> Chroot to this directory at the start, absolute path <value name = "chroot"> </value> Chdir to this directory at the start, absolute path <value name = "chdir"> </value> Redirect workers 'stdout and stderr into main error log. if not set, they will be redirected to/dev/null, according FastCGI specs <value name = "catch_workers_output"> yes </value> How much requests each process shoshould execute before respawn. useful to work around memory leaks in 3rd party libraries. for endless request processing please specify 0 Equivalent to PHP_FCGI_MAX_REQUESTS <value name = "max_requests"> 500 </value> <! -- Close when the number of requests is 500 --> Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect. equivalent to FCGI_WEB_SERVER_ADDRS environment in original php. fcgi (5.2.2 +) Makes sense only with AF_INET listening socket. <value name = "allowed_clients"> 127.0.0.1 </value> <! -- Access the ip address of fastcgi, for example: if the php request ip address forwarded by nginx is 192.168.1.101, it must be changed to 192.168.1.101 --> Pass environment variables like LD_LIBRARY_PATHAll $ VARIABLEs are taken from current environment <value name = "environment"> <value name = "HOSTNAME"> $ HOSTNAME </value> <value name = "PATH">/usr/local/bin: /usr/bin: /bin </value> <value name = "TMP">/tmp </value> <value name = "TMPDIR">/tmp </value> <value name = "TEMP ">/tmp </value> <value name =" OSTYPE "> $ OSTYPE </value> <value name =" MACHTYPE "> $ MACHTYPE </value> <value name = "MALLOC_CHECK _"> 2 </value> </section> </workers> </configuration>
Place a configuration file in php-fpmconf
Location: Open the/usr/local/php/etc/php-fpm.conf File
Change max_children from the previous 10 to the current 30, so that sufficient php-cgi processes can be used;
Change request_terminate_timeout from the previous 0 s to 60 s, so that the timeout time for the php-cgi process to process the script is 60 seconds, which can prevent the process from being suspended and improve the utilization efficiency.
Php-fpm start error:/etc/php-fpmconf: 1: parser error: Document is empty, parser error:
This is obviously a problem with the php-fpm.conf configuration file, I'll give you a copy of what I use
<Configuration>
All relative paths in this config are relative to php's install prefix
<Section name = "global_options">
Pid file
<Value name = "pid_file">/opt/php/logs/php-fpm.pid </value>
Error log file
<Value name = "error_log">/opt/php/logs/php-fpm.log </value>
Log level
<Value name = "log_level"> notice </value>
When this amount of php processes exited with SIGSEGV or SIGBUS...
<Value name = "emergency_restart_threshold"> 10 </value>
... In a less than this interval of time, a graceful restart will be initiated.
Useful to work around und accidental curruptions in accelerator's shared memory.
<Value name = "emergency_restart_interval"> 1 m </value>
Time limit on waiting child's reaction on signals from master
<Value name = "process_control_timeout"> 5 s </value>
Set to 'no' to debug fpm
<Value name = "daemonize"> yes </value>
</Section>
<Workers>
<Section name = "pool">
Name of pool. Used in logs and stats.
<Value name = "name"> default </value>
Address to accept fastcgi requests on.
Valid syntax is 'IP. ad. re. ss: port' or just 'po ...... the remaining full text>