Terug na blog
Januarie 13, 2026Gidse

Hoe om PHP-FPM te konfigureer vir optimale prestasie

Volledige gids oor die konfigurasie van PHP-FPM-poelinstellings, prestasie-instelling en integrasie met Nginx.

Hoe om PHP-FPM te konfigureer vir optimale prestasie

PHP-FPM (FastCGI Process Manager) is 'n alternatiewe PHP FastCGI-implementering met bykomende kenmerke wat nuttig is vir hoë-verkeer webwerwe. Behoorlike konfigurasie kan jou bediener se prestasie en hulpbronbenutting aansienlik verbeter.

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

Konfigureer PHP-FPM Poel

Wysig die poelkonfigurasielêer om prestasie te optimaliseer:

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

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

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

Prestasie-instelling

Optimaliseer PHP-FPM vir jou bediener se hulpbronne:

bash
# Bereken optimale max_children:
# (Totale RAM - Ander dienste) / (Geheue per PHP-proses)
# Voorbeeld: (2GB - 500MB) / 50MB = 30 max_children

# Wysig php.ini vir beter prestasie
sudo nano /etc/php/8.1/fpm/php.ini

# Aanbevole instellings:
memory_limit = 256M
max_execution_time = 300
upload_max_filesize = 64M
post_max_size = 64M

# Herbegin PHP-FPM
sudo systemctl restart php-fpm

Nginx-konfigurasie

Konfigureer Nginx om met PHP-FPM te werk:

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

# Voeg PHP-hantering by:
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;
}

# Toets en herlaai Nginx
sudo nginx -t
sudo systemctl reload nginx

Monitering van PHP-FPM

bash
# Gaan PHP-FPM status na
sudo systemctl status php-fpm

# Bekyk PHP-FPM prosesse
ps aux | grep php-fpm

# Gaan poelstatus na (indien statusbladsy geaktiveer)
curl http://localhost/status

# Bekyk logboeke
sudo tail -f /var/log/php8.1-fpm.log

PHP-FPM Optimaliseringswenke

  • Pas pm.max_children aan gebaseer op beskikbare RAM
  • Gebruik pm = dynamic vir die meeste gebruiksgevalle
  • Stel pm.max_requests om geheuelekke te voorkom
  • Aktiveer opcache vir beter prestasie
  • Monitor PHP-FPM status gereeld
  • Gebruik aparte poele vir verskillende toepassings
  • Hou PHP en PHP-FPM opgedateer