When working with PHP-FPM pool configurations, many developers face a dilemma: should we edit the original configuration files (like www.conf) directly, or is there a cleaner approach?
The main issues with direct edits are:
- Configuration changes get overwritten during package upgrades
- Makes it harder to track custom changes
- Creates maintenance headaches when migrating servers
PHP-FPM actually supports a powerful yet underdocumented feature – multiple configuration files for the same pool. Here's how it works:
# Original configuration (/etc/php/7.0/fpm/pool.d/www.conf)
[www]
user = www-data
group = www-data
pm.max_children = 5
pm.start_servers = 2
# Override file (/etc/php/7.0/fpm/pool.d/www-override.conf)
[www]
user = myapp
group = myapp
pm.max_children = 15
For this to work correctly:
- The override file must load after the original file (alphabetical order matters)
- Both files must declare the same pool name ([www] in this case)
- Only include directives you want to override in the second file
Always verify your configuration:
# Check for syntax errors
sudo php-fpm7.0 -t
# View merged configuration
sudo php-fpm7.0 -tt
# Reload configuration
sudo systemctl reload php7.0-fpm
In production environments:
- Use descriptive filenames (e.g., www-production-override.conf)
- Document your override files in your deployment scripts
- Consider versioning both original and override files
You can create multiple override files for different environments:
# Development override
[www]
pm.max_children = 10
pm.start_servers = 3
catch_workers_output = yes
# Production override
[www]
pm.max_children = 50
pm.start_servers = 10
request_terminate_timeout = 300s
This approach gives you maximum flexibility while keeping your base configuration clean and maintainable.
When managing PHP-FPM configurations, many administrators instinctively modify the default www.conf
file directly. While this works, it creates maintenance headaches:
[www]
user = www-data
group = www-data
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
After modification, the original values are lost, making upgrades problematic:
[www]
user = myapp # Overwritten
group = myapp # Overwritten
pm.max_children = 20 # Changed
PHP-FPM loads all .conf files in /etc/php/7.x/fpm/pool.d/
alphabetically. We can leverage this behavior:
- Keep original
www.conf
untouched - Create
www-overrides.conf
(alphabetically after www.conf)
Original www.conf
remains unchanged. Create a new file www-overrides.conf
:
[www]
; Only specify changed values
user = myapp
group = myapp
pm.max_children = 20
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
To verify the override works:
sudo php-fpm -t # Test configuration
sudo systemctl restart php-fpm
Check active settings:
sudo ps aux | grep php-fpm # Verify user/group
sudo systemctl status php-fpm # Check for errors
- Always keep override files alphabetically after the original
- Document overrides in comments
- Use clear naming conventions (e.g.,
zz-custom.conf
) - Test after PHP version upgrades
For complex setups, create multiple override files:
# Development
www-dev.conf:
[www]
pm.max_children = 10
# Production
www-prod.conf:
[www]
pm.max_children = 50