PHP-FPM Integration
When to Use PHP-FPM
Section titled “When to Use PHP-FPM”The native lsphp (LSAPI) is recommended for most deployments. Consider PHP-FPM when:
- You need to share the PHP process pool with another web server (e.g., during migration)
- Your hosting panel requires PHP-FPM (some control panels manage FPM pools exclusively)
- You need PHP-FPM-specific features like
access.logper pool orslowlog - You are running a multi-tenant setup where each user has an independent FPM pool
Install PHP-FPM
Section titled “Install PHP-FPM”RHEL / AlmaLinux / Rocky:
dnf install php-fpm# or a specific versiondnf install php84-php-fpmDebian / Ubuntu:
apt install php8.4-fpmConfigure PHP-FPM
Section titled “Configure PHP-FPM”TCP Socket (Port-based)
Section titled “TCP Socket (Port-based)”Edit /etc/php-fpm.d/www.conf (or /etc/php/8.4/fpm/pool.d/www.conf on Debian):
[www]user = www-datagroup = www-datalisten = 127.0.0.1:9000pm = dynamicpm.max_children = 20pm.start_servers = 5pm.min_spare_servers = 3pm.max_spare_servers = 10Unix Socket (Recommended)
Section titled “Unix Socket (Recommended)”Unix sockets avoid TCP overhead and are preferred for same-host setups:
[www]user = www-datagroup = www-datalisten = /run/php-fpm/www.socklisten.owner = nobodylisten.group = nobodylisten.mode = 0660pm = dynamicpm.max_children = 20pm.start_servers = 5pm.min_spare_servers = 3pm.max_spare_servers = 10Set listen.owner and listen.group to nobody (the user OLS runs as) so OLS can connect to the socket.
Start and enable PHP-FPM:
systemctl enable --now php-fpmConfigure OLS to Use PHP-FPM
Section titled “Configure OLS to Use PHP-FPM”External Application
Section titled “External Application”Add a fcgiapp (FastCGI application) extprocessor in httpd_config.conf:
TCP socket:
extprocessor phpfpm { type fcgiapp address 127.0.0.1:9000 maxConns 20 initTimeout 60 retryTimeout 0 persistConn 1 respBuffer 0 autoStart 0 path backlog 100 instances 1}Unix socket:
extprocessor phpfpm { type fcgiapp address uds://run/php-fpm/www.sock maxConns 20 initTimeout 60 retryTimeout 0 persistConn 1 respBuffer 0 autoStart 0 path backlog 100 instances 1}Key differences from lsphp configuration:
typeisfcgiappinstead oflsapiautoStartis0because PHP-FPM manages its own processesmaxConnsshould matchpm.max_childrenin the FPM pool
Script Handler
Section titled “Script Handler”scripthandler { add fcgi:phpfpm php}Note the handler type is fcgi (not lsapi).
Per-VHost PHP-FPM Pools
Section titled “Per-VHost PHP-FPM Pools”For multi-tenant hosting, create a separate FPM pool for each virtual host:
PHP-FPM pool (/etc/php-fpm.d/example.conf):
[example]user = exampleusergroup = exampleuserlisten = /run/php-fpm/example.socklisten.owner = nobodylisten.group = nobodylisten.mode = 0660pm = dynamicpm.max_children = 10pm.start_servers = 2pm.min_spare_servers = 1pm.max_spare_servers = 5OLS virtual host configuration:
virtualhost example { ... extprocessor phpfpm_example { type fcgiapp address uds://run/php-fpm/example.sock maxConns 10 autoStart 0 instances 1 }
scripthandler { add fcgi:phpfpm_example php }}PHP-FPM Status and Monitoring
Section titled “PHP-FPM Status and Monitoring”Enable FPM status in the pool:
pm.status_path = /fpm-statusping.path = /fpm-pingCreate an OLS context to allow access:
context /fpm-status { type fcgi handler phpfpm accessControl { allow 127.0.0.1 deny ALL }}Troubleshooting
Section titled “Troubleshooting”Connection refused:
- Verify PHP-FPM is running:
systemctl status php-fpm - Check the socket file exists and has correct permissions
- Ensure
listen.owner/listen.groupmatches the OLS user (nobody)
502 errors under load:
- Increase
pm.max_childrenin the FPM pool - Match OLS
maxConnstopm.max_children - Check FPM slow log for bottlenecks:
slowlog = /var/log/php-fpm/slow.log
File not found errors:
- Verify
SCRIPT_FILENAMEis being passed correctly - Ensure the document root is accessible to the FPM pool user
Next Steps
Section titled “Next Steps”- PHP LSAPI — compare with native LSAPI performance
- PHP Environment Variables — tune PHP settings