Terug naar blog
Januari 13, 2026Handleidingen

Hoe PHP-FPM te configureren voor optimale prestaties

Volledige handleiding over het configureren van PHP-FPM pool-instellingen, prestatieafstemming en integratie met Nginx.

Hoe PHP-FPM te configureren voor optimale prestaties

PHP-FPM (FastCGI Process Manager) is een alternatieve PHP FastCGI-implementatie met extra functies die nuttig zijn voor websites met veel verkeer. Een juiste configuratie kan de prestaties van uw server en het resourcegebruik aanzienlijk verbeteren.

PHP-FPM installeren

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 en schakel PHP-FPM in
sudo systemctl start php-fpm
sudo systemctl enable php-fpm

PHP-FPM-pool configureren

Bewerk het pool-configuratiebestand om de prestaties te optimaliseren:

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

# Belangrijke instellingen:
user = www-data
group = www-data
listen = /run/php/php8.1-fpm.sock
listen.owner = www-data
listen.group = www-data

# Procesbeheer
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_requests = 500

Prestatieafstemming

Optimaliseer PHP-FPM voor de bronnen van uw server:

bash
# Bereken optimale max_children:
# (Totale RAM - Andere services) / (Geheugen per PHP-proces)
# Voorbeeld: (2GB - 500MB) / 50MB = 30 max_children

# Bewerk php.ini voor betere prestaties
sudo nano /etc/php/8.1/fpm/php.ini

# Aanbevolen instellingen:
memory_limit = 256M
max_execution_time = 300
upload_max_filesize = 64M
post_max_size = 64M

# Herstart PHP-FPM
sudo systemctl restart php-fpm

Nginx-configuratie

Configureer Nginx om te werken met PHP-FPM:

bash
sudo nano /etc/nginx/sites-available/yourdomain.com

# Voeg PHP-afhandeling toe:
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 en herlaad Nginx
sudo nginx -t
sudo systemctl reload nginx

PHP-FPM monitoren

bash
# Controleer PHP-FPM status
sudo systemctl status php-fpm

# Bekijk PHP-FPM processen
ps aux | grep php-fpm

# Controleer poolstatus (indien statuspagina ingeschakeld)
curl http://localhost/status

# Bekijk logs
sudo tail -f /var/log/php8.1-fpm.log

Optimalisatietips voor PHP-FPM

  • Pas pm.max_children aan op basis van beschikbare RAM
  • Gebruik pm = dynamic voor de meeste scenario's
  • Stel pm.max_requests in om geheugenlekken te voorkomen
  • Schakel opcache in voor betere prestaties
  • Monitor regelmatig de PHP-FPM-status
  • Gebruik aparte pools voor verschillende applicaties
  • Houd PHP en PHP-FPM up-to-date