How to Tune Php-fpm Pool Settings for WordPress on Ubuntu Server

Knowing how to tune PHP-FPM pool settings for WordPress on Ubuntu Server is one of the most effective ways to improve your site’s speed and stability. By default, PHP-FPM ships with conservative settings that don’t suit every server. A high-traffic WordPress site will quickly hit those limits. You’ll see slow page loads, 502 errors, and spiking memory usage. This tutorial walks you through finding the right pool configuration for your specific server. You’ll learn how to calculate the correct number of PHP-FPM workers, choose the right process manager mode, and apply settings that match your available RAM. These changes can dramatically reduce server load and improve response times for your visitors.

Prerequisites and Requirements for PHP-FPM Pool Tuning

Before you start adjusting your PHP-FPM pool settings for WordPress on Ubuntu, make sure you have the following in place.

Required software and access:

  • Ubuntu Server 20.04 or 22.04 (this guide works for both)
  • PHP-FPM installed (version 7.4, 8.1, or 8.2)
  • WordPress installed and running
  • Nginx or Apache as your web server
  • Root or sudo access to the server

Assumed knowledge level:

You should be comfortable using the Linux command line. You don’t need to be an expert. Basic familiarity with editing files using nano or vim is enough.

Estimated time: 20–30 minutes.

You’ll also want to know how much RAM your server has. Run this command before you start:

free -m

Write down the total available memory. You’ll need it when calculating your worker count in the steps below. Check the official PHP-FPM configuration documentation if you want a full reference for every available directive.

How to Tune PHP-FPM Pool Settings for WordPress on Ubuntu

For a related walkthrough, see: How to Set Up Rabbitmq with Dead Letter Exchanges and Message Ttl for Reliable Task Processing on Ubuntu Server

Follow these steps carefully. Each one builds on the last.

Step 1: Find your PHP-FPM pool configuration file.

PHP-FPM stores pool configs in a specific directory. The path depends on your PHP version. For PHP 8.1, run:

ls /etc/php/8.1/fpm/pool.d/

You’ll see a file called www.conf. That’s the default pool file. Open it for editing:

sudo nano /etc/php/8.1/fpm/pool.d/www.conf

Step 2: Check your current process manager settings.

Scroll through the file and find the pm directive. It will look something like this:

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

These defaults are very low. They work for a tiny server but will choke under real WordPress traffic.

Step 3: Calculate the right number of PHP-FPM workers.

First, find out how much RAM one PHP-FPM process uses on average. Run this command:

ps --no-headers -o "rss,cmd" -C php-fpm8.1 | awk '{ sum+=$1 } END { printf "%.0f MBn", sum/NR/1024 }'

This gives you the average memory per worker in megabytes. A typical WordPress process uses between 30 MB and 80 MB.

Now use this formula:

Max Workers = (Total RAM - OS overhead) / Average worker size

For example, if you have 2 GB of RAM and each worker uses 50 MB, reserve about 400 MB for the OS and other services. That leaves 1,600 MB for PHP-FPM. Divide by 50 MB and you get 32 max workers.

Step 4: Choose the right process manager mode.

PHP-FPM offers three modes: static, dynamic, and ondemand.

  • static , Keeps a fixed number of workers running at all times. Best for high-traffic sites with consistent load.
  • dynamic , Scales workers up and down within limits. Good for most WordPress sites.
  • ondemand , Spawns workers only when needed. Best for low-traffic or memory-constrained servers.

For most WordPress sites, use dynamic.

Step 5: Apply your new PHP-FPM pool settings.

Based on your calculations, update the pool file. Here’s an example configuration for a 2 GB server:

pm = dynamic
pm.max_children = 30
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 10
pm.max_requests = 500

The pm.max_requests directive tells each worker to restart after handling 500 requests. This prevents memory leaks from building up over time. It’s a simple but powerful setting.

Step 6: Tune additional performance directives.

Add or update these settings in the same pool file:

request_terminate_timeout = 120
php_admin_value[memory_limit] = 256M
php_admin_value[upload_max_filesize] = 64M
php_admin_value[post_max_size] = 64M

The request_terminate_timeout kills any PHP process that runs longer than 120 seconds. This protects your server from runaway scripts.

Step 7: Save the file and reload PHP-FPM.

Press Ctrl + X, then Y, then Enter to save in nano. Now reload PHP-FPM to apply the changes:

sudo systemctl reload php8.1-fpm

Check that it reloaded without errors:

sudo systemctl status php8.1-fpm

You should see active (running) in the output.

Step 8: Monitor your pool after changes.

Enable the PHP-FPM status page to watch your pool in real time. Add this to your pool file:

pm.status_path = /status

Then configure your Nginx server block to expose it internally. After reloading, visit http://your-server-ip/status to see live worker stats. Watch the active processes and max children reached counters. If max children reached keeps climbing, increase pm.max_children.

Troubleshooting Common PHP-FPM Pool Problems

Even with the right settings, things can go wrong. Here are the most common issues and how to fix them.

502 Bad Gateway errors:

This usually means PHP-FPM ran out of workers. Check your error log:

sudo tail -f /var/log/php8.1-fpm.log

Look for lines saying max_children was reached. If you see them, increase pm.max_children and reload.

PHP-FPM fails to start after editing the config:

Run this command to check for syntax errors before reloading:

sudo php-fpm8.1 --test

It will tell you exactly which line has a problem.

Memory usage keeps growing:

Lower pm.max_requests to something like 200 or 300. This forces workers to restart more often. It clears any memory that WordPress plugins might be leaking.

WordPress is still slow after tuning:

PHP-FPM is just one piece of the puzzle. Make sure you also have a caching plugin active. W3 Total Cache is a popular option that works well with PHP-FPM and Nginx. Object caching with Redis or Memcached will also help significantly.

Wrong PHP version path:

If you’re on PHP 8.2, replace 8.1 with 8.2 in all commands and file paths. Always confirm your active PHP version with php -v before editing any config files.

Conclusion

You now know how to tune PHP-FPM pool settings for WordPress on Ubuntu Server from start to finish. You’ve learned how to calculate the right number of workers, pick the correct process manager mode, and apply settings that match your server’s available memory. These changes reduce 502 errors, lower memory pressure, and help WordPress handle more concurrent visitors without extra hardware. The key is to monitor your pool after making changes and adjust based on real traffic data. Don’t set values and forget them. Check your status page and logs regularly. From here, consider pairing these PHP-FPM optimizations with Nginx microcaching or a Redis object cache for even better results.

Similar Posts