PHP-FPM 8.x Optimization Guide for High Performance WordPress (Ubuntu)
Table of Contents
Optimizing PHP-FPM 8.x is one of the most impactful steps you can take to dramatically improve WordPress performance.
A properly tuned PHP environment reduces server load, improves response times, and allows your website to handle significantly more traffic.
In this guide, you’ll learn how to configure php.ini and PHP-FPM pool settings for maximum performance, stability, and scalability.
Why PHP-FPM Optimization Matters
WordPress is heavily dependent on PHP execution. Every page load triggers PHP processes, database queries, and file operations.
Without optimization:
- CPU usage spikes under load
- Memory gets exhausted quickly
- Response times increase
- Server crashes become more likely
With proper tuning, you can achieve:
- Faster page load times
- Lower server resource usage
- Higher concurrent user capacity
- Improved stability under traffic spikes
1. Core PHP Settings (php.ini)
Edit your PHP configuration file:
sudo nano /etc/php/8.x/fpm/php.iniMemory and Execution Limits
memory_limit = 256M
max_execution_time = 60
max_input_time = 60These values ensure scripts have enough resources while preventing runaway processes from consuming server memory.
Input Variables
max_input_vars = 3000Important for WordPress admin operations, especially when using page builders or large forms.
File Upload Limits
upload_max_filesize = 64M
post_max_size = 64MSupports media uploads and plugin installations without errors.
2. OPcache Optimization (Critical Performance Boost)
OPcache stores compiled PHP scripts in memory, eliminating the need to recompile them on every request.
This is the single most important optimization for PHP performance.
opcache.enable=1
opcache.enable_cli=0
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=20000
opcache.max_wasted_percentage=10
opcache.validate_timestamps=0
opcache.revalidate_freq=0
opcache.jit=offImportant Note
When opcache.validate_timestamps=0 is enabled, PHP will not detect file changes automatically.
You must manually restart PHP-FPM after updates:
sudo systemctl restart php8.x-fpm3. Realpath Cache Optimization
This setting reduces filesystem lookups and significantly improves performance for large WordPress installations.
realpath_cache_size = 4096K
realpath_cache_ttl = 6004. Disable Performance-Impacting Features
expose_php = Off
display_errors = Off
log_errors = On
allow_url_fopen = Off
allow_url_include = OffDisabling unnecessary features improves both performance and security.
5. PHP-FPM Pool Configuration (Most Important)
Edit the pool configuration file:
sudo nano /etc/php/8.x/fpm/pool.d/www.confProcess Manager
pm = dynamicDynamic mode adjusts processes based on traffic, balancing performance and resource usage.
Worker Configuration Example
pm.max_children = 20
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6These values depend on your server RAM and CPU. Proper tuning prevents overload and maximizes concurrency.
Process Recycling
pm.max_requests = 500Prevents memory leaks by restarting workers periodically.
Slow Log Monitoring
request_slowlog_timeout = 5s
slowlog = /var/log/php8.x-fpm.slow.logHelps identify slow plugins and performance bottlenecks.
6. Enable PHP-FPM Status Page
pm.status_path = /statusNginx configuration:
location /status {
allow 127.0.0.1;
deny all;
include fastcgi_params;
fastcgi_pass unix:/run/php/php8.x-fpm.sock;
}This provides real-time insight into PHP performance and active processes.
7. Session Optimization
session.gc_maxlifetime = 1440
session.save_handler = filesFor high-traffic sites, consider switching to Redis for session handling to improve scalability.
8. Advanced Optimization (Optional)
opcache.huge_code_pages=1This enables huge memory pages, reducing CPU overhead and improving execution speed.
9. Apply Changes
Restart PHP-FPM after making changes:
sudo systemctl restart php8.x-fpmBest Practices for Maximum Performance
- Combine OPcache with Redis object caching
- Use Nginx FastCGI caching where possible
- Monitor slow logs regularly
- Keep PHP and WordPress updated
- Optimize database queries
Common Mistakes to Avoid
- Setting
pm.max_childrentoo high (causes RAM exhaustion) - Leaving OPcache validation enabled in production
- Ignoring slow logs
- Not restarting PHP after configuration changes
FAQ
What is the best pm setting for PHP-FPM?
The best setting depends on your server resources. For most WordPress sites, pm = dynamic offers the best balance between performance and memory usage.
How do I calculate pm.max_children?
Divide total available RAM by the average memory usage per PHP process. This ensures you don’t overload your server.
Is OPcache really necessary?
Yes. OPcache can improve PHP performance by several times by caching compiled scripts in memory.
Should I disable opcache.validate_timestamps?
Yes, in production environments. It improves performance, but requires manual PHP restarts after updates
What is the biggest performance gain?
Enabling and properly tuning OPcache provides the most noticeable performance improvement.
Do I need Redis?
Not required, but highly recommended for high-traffic WordPress sites to reduce database load.
Conclusion
Optimizing PHP-FPM 8.x is essential for achieving high performance in WordPress. By tuning OPcache, adjusting PHP-FPM workers, and disabling unnecessary features, you can significantly improve your server’s efficiency and scalability.
Apply these settings carefully, monitor performance, and adjust based on your server’s workload for the best results.