Skip to content

PHP-FPM

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with features useful for high-load websites.

Terminal window
# Ubuntu/Debian
sudo apt install php-fpm
# Check version
php-fpm -v
# Check status
sudo systemctl status php8.2-fpm
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

/etc/php/8.2/fpm/pool.d/www.conf:

[www]
user = www-data
group = www-data
listen = /var/run/php/php8.2-fpm.sock
; Process management
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
; Logging
access.log = /var/log/php-fpm/access.log
slowlog = /var/log/php-fpm/slow.log
request_slowlog_timeout = 5s
ModeDescriptionBest For
staticFixed number of childrenPredictable load
dynamicScales based on demandMost cases
ondemandSpawns on requestLow traffic
Terminal window
sudo systemctl start php8.2-fpm
sudo systemctl stop php8.2-fpm
sudo systemctl restart php8.2-fpm
sudo systemctl reload php8.2-fpm # Graceful reload
AspectPHP-FPMPythonNode.js
ModelProcess poolSingle processEvent loop
MemoryPer-requestPersistentPersistent
ScalingFPM handlesSupervisor/PM2PM2 cluster
Best ForWeb pagesAPIs, scriptsReal-time