What is PHP-FPM, and what role does it play in serving PHP applications through a web server like Nginx?
Short answer
PHP-FPM, or FastCGI Process Manager, is a PHP implementation that manages a pool of worker processes ready to handle incoming PHP requests, working alongside a web server like Nginx which handles serving static files and forwards PHP specific requests to PHP-FPM for actual…
Advertisement
AModel answer
PHP-FPM, or FastCGI Process Manager, is a PHP implementation that manages a pool of worker processes ready to handle incoming PHP requests, working alongside a web server like Nginx which handles serving static files and forwards PHP specific requests to PHP-FPM for actual processing, and this separation of concerns generally provides better performance and more flexible process management compared to older, simpler PHP execution models.
# Nginx configuration snippet
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_index index.php;
}Real-world example
A production server runs Nginx to efficiently serve static assets like images and CSS files directly, while forwarding any request for a PHP file to a properly configured pool of PHP-FPM worker processes for execution.
Likely follow-ups
- How do you configure the number of worker processes in a PHP-FPM pool?
- What is the difference between PHP-FPM and the older mod_php approach with Apache?
Related topics