What is PHP-FPM and Why Configure It
PHP-FPM (FastCGI Process Manager) runs PHP as a separate service. Paired with Nginx, it delivers high performance: Nginx handles static files while PHP-FPM handles dynamic requests. Proper PHP-FPM tuning can serve 2–5x more requests without adding RAM.
Pool Configuration File
sudo nano /etc/php/8.2/fpm/pool.d/www.confProcess Manager Modes
| Mode | Description | When to Use |
|---|---|---|
static | Fixed number of processes | High-traffic servers with enough RAM |
dynamic | Process count adjusts dynamically | Most VPS (recommended) |
ondemand | Processes created on demand | Low-traffic, RAM conservation |
Optimal pm Settings for dynamic Mode
pm = dynamic
pm.max_children = 20
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 8
pm.max_requests = 500Formula for pm.max_children: Divide available RAM by average PHP process size. Example: 2 GB RAM, 80 MB per process → max_children = 25. Check average size:
ps -o rss= -C php-fpm8.2 | awk '{ sum+=$1 } END { print sum/NR/1024 " MB" }'Slow Log
slowlog = /var/log/php8.2-fpm-slow.log
request_slowlog_timeout = 5sApply Configuration
sudo systemctl reload php8.2-fpmUse
reload instead of restart to avoid dropping active connections.