While mpm prefork is not the fastest mpm available for Apache2 web servers and also does not support HTTP/2 and ALPN, it is thread-safe and not closest to slower when the number of traffic is lower and CDN is extensively used. PHP FPM is faster but demands a somewhat expert person to optimize. That is the reason why some people still prefer mod_php and mpm prefork.
The above paragraphs explain why we are discussing optimizing
php.ini for WordPress when
mod_php and mpm prefork are used. Like all the Apache2 modules,
mod_php directives provide functionality specific for php parsing, and some others can be set in
php.ini settings. There is a WordPress plugin named “Health Check & Troubleshooting” (it is by WordPress core developers) which can help you.
This a safe yet effective configuration for mpm prefork:
- StartServers is the number of child processes created upon starting Apache.
- MaxRequestWorkers is the maximum number of connections that can be open at one time. After reaching this limit, the next incoming connections will be queued.
- MinSpareServers and MaxSpareServers refer to the number of child processes that should be idle at any one time.
- MaxConnectionsPerChild determines the total number of connections each child process can serve before it is restarted. This safeguards against memory leaks when using mod_php.
You can set MaxConnectionsPerChild to a high value (e.g. 1,000) rather than leaving it to 0 (= unlimited). You have to set the allowed PHP limit for your WordPress installation from the
512MB is more than enough for each PHP process. Most of the managed WordPress hosting keeps it around 256MB. On php.ini files, you need to the settings to these example values:
upload_max_filesize = 32M
post_max_size = 48M
memory_limit = 1024M
max_execution_time = 600
max_input_vars = 1000
max_input_time = 400
php.ini file to modify? Run
locate command to find the locations:
Usually, the loaded configuration file is in the CLI directory, but you should also modify the
php.ini file which is under Apache’s directory. The CGI one is not related to the present settings.