What Is PHP-FPM?

Category: Web Servers ยท Updated 2026-11-10

PHP-FPM (FastCGI Process Manager) is an implementation of PHP that runs the language as a managed pool of separate worker processes, instead of loading PHP directly inside the web server. Nginx and modern Apache setups hand PHP requests to this pool over FastCGI, which gives better control over memory, concurrency and isolation than older approaches like mod_php.

Why PHP-FPM exists

Early setups ran PHP as a module directly inside Apache (mod_php), which embeds the PHP interpreter in every Apache worker, even when it is serving a plain image. PHP-FPM separates PHP into its own process manager that the web server talks to only when a request actually needs PHP. This keeps static file requests light, lets PHP run under its own user and permissions, and lets administrators tune PHP's concurrency independently of the web server's own connection handling.

How PHP-FPM connects to the web server

PHP-FPM listens on a Unix socket or a TCP port and speaks the FastCGI protocol. Nginx, which has no built-in PHP support, forwards matching requests to it with a fastcgi_pass directive. Apache reaches it through a module such as mod_proxy_fcgi. In both cases, the web server handles the HTTP connection and static files, while PHP-FPM only executes the PHP code and returns the result.

# Example Nginx location block
location ~ \.php$ {
    fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

Pools and process manager modes

PHP-FPM organizes workers into pools, each with its own user, resource limits and PHP settings, which is how a server can run several sites under different PHP versions or permissions. Each pool runs in one of three process manager modes:

ModeBehaviorGood for
staticA fixed number of worker processes, always runningPredictable, high-traffic sites with stable load
dynamicStarts with a base number and spawns more up to a maximum as demand rises, then kills idle onesMost general-purpose sites, the common default
ondemandStarts no workers until a request arrives, then scales down to zero when idleLow-traffic or memory-constrained servers

Key configuration directives

Pool settings usually live in a file such as /etc/php/8.3/fpm/pool.d/www.conf on Debian-based systems. The most commonly tuned directives are:

pm = dynamic
pm.max_children = 20
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 8

pm.max_children caps how many PHP requests can run at once; set too low, requests queue up and slow down, set too high on a server without enough RAM, the server can run out of memory. A rough starting point is to divide available RAM for PHP by the typical memory used per PHP process.

Common problems and how to diagnose them

  • 502 Bad Gateway: usually means PHP-FPM crashed, is not running, or the socket path in the web server config does not match the pool's actual socket.
  • 504 Gateway Timeout: a PHP script is taking longer than the configured timeout, often from a slow database query or an external API call.
  • Requests queuing under load: pm.max_children is reached; check the PHP-FPM status page or slow log to confirm.
  • High memory use: too many max children for the server's RAM, or a memory leak in application code.

PHP-FPM's own error log and optional slow log (enabled with slowlog and request_slowlog_timeout) are usually the fastest way to confirm which of these is happening.

Frequently asked questions

What does PHP-FPM stand for?

PHP-FPM stands for PHP FastCGI Process Manager. It is an alternative way of running PHP that manages a pool of worker processes instead of embedding PHP directly in the web server.

What is the difference between PHP-FPM and mod_php?

mod_php embeds the PHP interpreter directly inside each Apache worker process, while PHP-FPM runs PHP as a separate, independently configured pool of processes that the web server talks to over FastCGI. PHP-FPM generally uses memory more efficiently and allows per-site tuning.

Does Nginx need PHP-FPM to run PHP?

Yes. Nginx has no built-in ability to execute PHP, so it must forward PHP requests to PHP-FPM (or another FastCGI-compatible processor) using a fastcgi_pass directive.

What causes a 502 Bad Gateway error with PHP-FPM?

A 502 usually means the web server could not reach PHP-FPM at all, because the service crashed, is not running, or the socket or port in the web server configuration does not match the pool's actual listening address.

What does pm.max_children control?

It sets the maximum number of PHP-FPM worker processes allowed to run at the same time. Setting it too low causes requests to queue during traffic spikes, and setting it too high without enough RAM can exhaust server memory.

Can one server run multiple PHP versions with PHP-FPM?

Yes. Each PHP-FPM pool can run its own PHP version and settings, so a server can host one site on PHP 8.1 and another on PHP 8.3 at the same time by routing each domain to the matching pool's socket.

Related topics