Pcornel
Browse topics
Options
Recent
Favorites
Web Infrastructure · Technical reference

PHP-FPM

Direct answer

PHP-FPM (FastCGI Process Manager) runs PHP as a pool of worker processes that a web server (nginx, Apache, Caddy) talks to over FastCGI on a Unix socket or TCP port.

When to use this

Use it for every modern PHP deployment behind nginx or Apache event MPM; size pools to memory, isolate sites in separate pools and users, and read its status page when PHP pages slow down or return 502/504.

First 30 seconds

1. Is FPM running and listening where the web server expects (socket path/port)?

2. Can the web server user access the socket?

3. Is the pool at max children with a listen queue?

4. Are slow requests in the slowlog (database, external API)?

Operational verification

web server location → fastcgi_pass (socket/TCP) → FPM pool listen queue → worker process (pm) → PHP script → response → web server

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
PHP-FPM (PHP 8.x); Debian/Ubuntu paths shown, RHEL uses /etc/php-fpm.d and php-fpm.service.
Applicability is projected only from persisted Topic profile and Command metadata.
At a glance

Operational reference

Fast context before you go deeper.

PlatformPHP-FPM (PHP 8.x); Debian/Ubuntu paths shown, RHEL uses /etc/php-fpm.d and php-fpm.service.
Key commandsystemctl status php8.2-fpm
Scope / prerequisiteUse it for every modern PHP deployment behind nginx or Apache event MPM; size pools to memory, isolate sites in separat…
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

3 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Read-only Verification Verify boundary
# Service and configuration
systemctl status php8.2-fpm
php-fpm8.2 -t

# Is the socket there, and who may use it?
ls -l /run/php/

# Status page through the web server (location restricted to localhost)
curl -s 'http://127.0.0.1/fpm-status?full' | head -20

# Pool exhaustion and slow requests
grep -i 'max_children' /var/log/php8.2-fpm.log | tail
tail -n 50 /var/log/php-fpm/shop-slow.log

listen queue above 0 or a rising max children reached means the pool is too small for the load or requests are too slow; the slowlog's PHP backtraces show which function was running (often a database call or an external HTTP request).

Step 2 Common mistakes Narrow the fault
  • One shared pool and user for every site.
  • Setting pm.max_children far above what memory can hold.
  • Exposing FastCGI on a TCP port to the network.
  • Passing every URL ending in .php to FPM without checking that the file exists.
  • Leaving the status page public.
Step 3 Troubleshooting Narrow the fault

502 Bad Gateway, error log: connect() to unix:/run/php/... failed (2: No such file or directory). FPM is stopped, the pool failed to start, or the socket path differs between FPM and the web server (often after a PHP version upgrade: php8.1 → php8.2 socket name).

502 with (13: Permission denied). The web server user cannot access the socket; fix listen.owner/group/mode.

504 Gateway Timeout / upstream timed out. Workers are busy or a script is slow. Check status (queue, max children) and the slowlog.

Log says server reached pm.max_children setting. Raise pm.max_children only if memory allows; otherwise fix slow requests or add capacity.

"File not found." or "Primary script unknown". Wrong SCRIPT_FILENAME (document root mismatch) or the pool user cannot read the file.

Key points

pm.max_children caps concurrent PHP requests — when it is reached, requests queue and the log says 'server reached pm.max_children'. 502 = web server could not talk to FPM (socket missing, permissions, FPM down); 504 = FPM accepted but answered too slowly. Never expose the FastCGI port publicly.

Key checks
  • systemctl status php8.2-fpm (name varies by distro/version) — running, pools.
  • php-fpm8.2 -t — configuration test.
  • Status page (pm.status_path = /status) — active/idle processes, listen queue, max children reached, slow requests.
  • grep -i 'max_children' /var/log/php8.2-fpm.log — pool exhaustion.
  • Web server error log: 'connect() to unix:/run/php/... failed' or 'upstream timed out'.
ReferenceWhat it is2 sections · depth on demand

Direct Answer

PHP-FPM runs PHP in pools of worker processes. The web server does not execute PHP itself: it forwards each PHP request over FastCGI to a pool's socket, a free worker runs the script, and the result goes back to the web server. The process manager (pm) decides how many workers exist — static, dynamic or ondemand — and pm.max_children is the hard cap on concurrent PHP requests. Most PHP outages are either the web server failing to reach the socket (502) or a pool that is full or slow (504).

ReferenceImportant terms & boundaries1 section · depth on demand

In depth

Pools

Each pool ([www], [shop]…) has its own user/group, listen socket, process-manager settings and PHP overrides (php_admin_value[...]). One pool per site isolates file permissions, resource use and crashes.

Process manager

pmBehaviourMain directives
staticFixed number of workerspm.max_children
dynamicBetween spare limits, up to the maximumpm.max_children, pm.start_servers, pm.min_spare_servers, pm.max_spare_servers
ondemandSpawns on request, kills idle workerspm.max_children, pm.process_idle_timeout (default 10 s)

pm.max_requests recycles a worker after N requests (0 = never), a workaround for memory leaks.

Sizing

Measure the resident memory of a typical worker under load (ps -o rss -C php-fpm8.2) and set pm.max_children to roughly *(RAM available for PHP) ÷ (average worker RSS)*, leaving room for the database, web server and page cache. More workers than CPU and memory can serve only moves the queue into swap.

Socket and permissions

[shop]
user = shop
group = shop
listen = /run/php/php8.2-fpm-shop.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
pm = dynamic
pm.max_children = 20
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
pm.max_requests = 500
pm.status_path = /fpm-status
ping.path = /fpm-ping
request_slowlog_timeout = 5s
slowlog = /var/log/php-fpm/shop-slow.log
request_terminate_timeout = 120s

The web server user needs read/write on the socket. For TCP listeners, set listen.allowed_clients and never publish the port: an exposed FastCGI endpoint allows arbitrary code execution.

Web server side (nginx)

location ~ \.php$ {
    try_files $uri =404;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/run/php/php8.2-fpm-shop.sock;
    fastcgi_read_timeout 120s;
}

try_files $uri =404 prevents nginx from passing non-existent paths (for example an uploaded image with /x.php appended) to PHP. Apache uses mod_proxy_fcgi with SetHandler "proxy:unix:/run/php/php8.2-fpm-shop.sock|fcgi://localhost".

Timeouts

Three limits interact: PHP's max_execution_time, FPM's request_terminate_timeout (kills the worker, also when PHP's limit does not apply), and the web server's fastcgi_read_timeout (default 60 s in nginx). Keep the web server timeout at least as long as the longest legitimate request, and use the slowlog to find what is slow.

Status page fields

FieldMeaning
accepted connRequests accepted since start
listen queueRequests waiting for a free worker — should be 0
max listen queueHighest queue since start
idle / active processesCurrent workers
max active processesPeak concurrency
max children reachedTimes the pool hit pm.max_children
slow requestsRequests over request_slowlog_timeout

Protect the status and ping paths so only localhost or monitoring can reach them. pm.status_listen (PHP 8.0+) serves status from a separate listener that stays reachable when the pool is busy.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
php-fpmphp fpmfastcgi process managerpm.max_childrenfastcgi_passphp-fpm status
Confirmation

Confirm action

Continue?