Apache can run PHP through two fundamentally different methods — mod_php (embedded directly in Apache) or PHP-FPM (a separate FastCGI process manager). This guide explains the difference and helps you choose.
mod_php: The Traditional Approach
PHP runs embedded directly within each Apache worker process — simple to set up, but means every Apache process carries PHP's full memory overhead, even when serving non-PHP requests.
PHP-FPM: The Modern, Decoupled Approach
PHP runs as a separate pool of worker processes, with Apache (or Nginx) forwarding PHP requests to it via FastCGI — more efficient memory usage, and the same PHP-FPM setup can be shared between Apache and Nginx if you're ever migrating between them.
Key Differences
| Factor | mod_php | PHP-FPM |
|---|---|---|
| Memory efficiency | Lower — every worker carries PHP overhead | Higher — PHP processes are separate and can be tuned independently |
| Setup complexity | Simpler, fewer moving parts | Slightly more configuration |
| Process isolation | PHP tied directly to Apache's process model (prefork MPM required) | Independent process pool, works with more efficient Apache MPMs |
| Performance under load | Generally lower | Generally better, especially at scale |
Why PHP-FPM Enables Better Apache Performance
mod_php requires Apache's older "prefork" MPM (Multi-Processing Module); PHP-FPM lets you use Apache's more efficient "event" or "worker" MPM instead, since PHP processing is decoupled from Apache's own worker processes — a meaningful performance advantage under concurrent load.
Installing PHP-FPM
sudo apt install php-fpm libapache2-mod-fcgid -y
Configuring Apache to Use PHP-FPM
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php8.2-fpm.sock|fcgi://localhost"
</FilesMatch>
Switching Apache to the Event MPM
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event
sudo a2enmod proxy_fcgi
sudo systemctl restart apache2
Verifying PHP-FPM Is Active
<?php phpinfo(); ?>
Check the "Server API" value in the output — should show "FPM/FastCGI" rather than "Apache 2.0 Handler" (which indicates mod_php).
When mod_php Might Still Be Reasonable
For very small, low-traffic sites where the performance difference is negligible and simplicity is prioritized, mod_php remains a functional (if not optimal) choice — but for anything with meaningful traffic or where you want headroom to scale, PHP-FPM is the better foundation.
Tuning PHP-FPM Process Pools
sudo nano /etc/php/8.2/fpm/pool.d/www.conf
pm = dynamic
pm.max_children = 20
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
Tune based on available RAM and expected concurrent PHP request volume — too few children causes request queuing under load; too many risks exhausting server memory.
Common Errors
502 Bad Gateway after switching to PHP-FPM — verify the socket path in the Apache configuration exactly matches PHP-FPM's actual listening socket, and that PHP-FPM is running (systemctl status php8.2-fpm).
Continue Reading
- How to Install Apache on Ubuntu & Debian (Complete Guide)
- How to Deploy WooCommerce on a VPS (Complete Guide)
- Nginx Performance Tuning: Worker Processes, Caching & Gzip
Browse more articles in Web Servers.