January 13, 2026Guides
How to Configure PHP-FPM for Optimal Performance
Complete guide on configuring PHP-FPM pool settings, performance tuning, and integration with Nginx.

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with additional features useful for high-traffic websites. Proper configuration can significantly improve your server's performance and resource utilization.
Installing PHP-FPM
bash
# Ubuntu/Debian
sudo apt update
sudo apt install php-fpm php-mysql php-mbstring php-xml php-curl -y
# CentOS/RHEL
sudo yum install php-fpm php-mysql php-mbstring php-xml php-curl -y
# Start and enable PHP-FPM
sudo systemctl start php-fpm
sudo systemctl enable php-fpmConfiguring PHP-FPM Pool
Edit the pool configuration file to optimize performance:
bash
sudo nano /etc/php/8.1/fpm/pool.d/www.conf
# Key settings:
user = www-data
group = www-data
listen = /run/php/php8.1-fpm.sock
listen.owner = www-data
listen.group = www-data
# Process management
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_requests = 500Performance Tuning
Optimize PHP-FPM for your server's resources:
bash
# Calculate optimal max_children:
# (Total RAM - Other services) / (Memory per PHP process)
# Example: (2GB - 500MB) / 50MB = 30 max_children
# Edit php.ini for better performance
sudo nano /etc/php/8.1/fpm/php.ini
# Recommended settings:
memory_limit = 256M
max_execution_time = 300
upload_max_filesize = 64M
post_max_size = 64M
# Restart PHP-FPM
sudo systemctl restart php-fpmNginx Configuration
Configure Nginx to work with PHP-FPM:
bash
sudo nano /etc/nginx/sites-available/yourdomain.com
# Add PHP handling:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Test and reload Nginx
sudo nginx -t
sudo systemctl reload nginxMonitoring PHP-FPM
bash
# Check PHP-FPM status
sudo systemctl status php-fpm
# View PHP-FPM processes
ps aux | grep php-fpm
# Check pool status (if status page enabled)
curl http://localhost/status
# View logs
sudo tail -f /var/log/php8.1-fpm.logPHP-FPM Optimization Tips
- Adjust pm.max_children based on available RAM
- Use pm = dynamic for most use cases
- Set pm.max_requests to prevent memory leaks
- Enable opcache for better performance
- Monitor PHP-FPM status regularly
- Use separate pools for different applications
- Keep PHP and PHP-FPM updated