PHP-FPM with separate pools for web hosting customers
Summary
In June 2022 Manuel Schmitt reports that manitu moved its entire web hosting platform to PHP-FPM within a week and a half. Every web hosting package gets its own FPM pool running with the package's user, group and umask, and the old Apache PHP module is gone. A self-written Apache module ignores old php_flag and php_value lines so that affected sites do not return an error 500.
From Apache module to process pool
With the Apache module, PHP runs inside the web server process itself; according to Manuel Schmitt, at manitu it already ran under the package's user and group. PHP-FPM, by contrast, is a separate FastCGI service that has been part of the PHP core since PHP 5.3.3 in July 2010. Its pools start worker processes with their own uid, gid and settings.
The trigger was a customer who pointed out a flaw in the old setup; the switch had originally been planned for the third quarter.
What happens to php_flag in .htaccess
The php_flag and php_value directives in an .htaccess file only work with the Apache module. Without the module and without a protective IfModule block, they break the site with an error 500. manitu contacted affected customers and catches these lines with its own module.
For FastCGI, the PHP manual provides .user.ini files instead. PHP reads them from the script's directory upwards to the document root and reloads them every 300 seconds by default.
Ideas
- Separate FPM pools run PHP with the user, group and umask of each package.
- A customer's hint moved the planned switch forward by a quarter.
- According to the operator, the migration makes WordPress and Nextcloud faster.
- A custom Apache module ignores old php_flag and php_value lines instead of raising error 500.
- Separate PHP error logs make diagnosis easier for customers.
- .user.ini replaces PHP directives in .htaccess under FastCGI.
Insights
- Compatibility layers can decouple large platform migrations without legitimising legacy permanently.
- Tenant separation gets stronger when runtime processes share the ownership boundaries of customer data.
- A self-developed platform allows transitional solutions that standard packages do not offer.
Facts
- Every web hosting package received its own FPM pool.
- PHP errors are then written separately to /logs/php.err.log.
- The FastCGI Process Manager has been part of the PHP core since PHP 5.3.3 in July 2010.
- .user.ini files are only processed by the CGI and FastCGI SAPIs.
- user_ini.cache_ttl defaults to 300 seconds.
References
- Manuel Schmitt on Hostblogger: original article (German)
- PHP Manual: FastCGI Process Manager (FPM)
- PHP Manual: .user.ini files
Recommendations
- Measure latency, memory usage and error rate before and after the switch.
- Move php_value settings from .htaccess into a .user.ini.
- Allow up to five minutes for changed .user.ini values to take effect.
- Remove outdated php_flag rules after a documented transition period.
Read the original article on Hostblogger
Found a mistake or have something to add? Get in touch.
Links to the original source and the Web Archive open in a new tab.