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:

Shell
sudo nano /etc/php/8.x/fpm/php.ini

Memory and Execution Limits

INI
memory_limit = 256M
max_execution_time = 60
max_input_time = 60

These values ensure scripts have enough resources while preventing runaway processes from consuming server memory.

Input Variables

INI
max_input_vars = 3000

Important for WordPress admin operations, especially when using page builders or large forms.

File Upload Limits

INI
upload_max_filesize = 64M
post_max_size = 64M

Supports 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.

INI
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=off

Important Note

When opcache.validate_timestamps=0 is enabled, PHP will not detect file changes automatically.
You must manually restart PHP-FPM after updates:

Shell
sudo systemctl restart php8.x-fpm

3. Realpath Cache Optimization

This setting reduces filesystem lookups and significantly improves performance for large WordPress installations.

INI
realpath_cache_size = 4096K
realpath_cache_ttl = 600

4. Disable Performance-Impacting Features

INI
expose_php = Off
display_errors = Off
log_errors = On

allow_url_fopen = Off
allow_url_include = Off

Disabling unnecessary features improves both performance and security.

5. PHP-FPM Pool Configuration (Most Important)

Edit the pool configuration file:

Shell
sudo nano /etc/php/8.x/fpm/pool.d/www.conf

Process Manager

INI
pm = dynamic

Dynamic mode adjusts processes based on traffic, balancing performance and resource usage.

Worker Configuration Example

INI
pm.max_children = 20
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6

These values depend on your server RAM and CPU. Proper tuning prevents overload and maximizes concurrency.

Process Recycling

INI
pm.max_requests = 500

Prevents memory leaks by restarting workers periodically.

Slow Log Monitoring

INI
request_slowlog_timeout = 5s
slowlog = /var/log/php8.x-fpm.slow.log

Helps identify slow plugins and performance bottlenecks.

6. Enable PHP-FPM Status Page

INI
pm.status_path = /status

Nginx configuration:

NGINX
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

INI
session.gc_maxlifetime = 1440
session.save_handler = files

For high-traffic sites, consider switching to Redis for session handling to improve scalability.

8. Advanced Optimization (Optional)

INI
opcache.huge_code_pages=1

This enables huge memory pages, reducing CPU overhead and improving execution speed.

9. Apply Changes

Restart PHP-FPM after making changes:

Shell
sudo systemctl restart php8.x-fpm

Best 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_children too 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.

← Nginx Hardening for WordPress: Complete Security Guide (Step-by-Step) When (and How) to Split Your WordPress Database →
Share this page
Back to top