FastCGI and PHP-FPM architecture
Two processes, two responsibilities
Nginx accepts HTTP requests and can serve a CSS file directly. PHP-FPM is a separate process manager that runs PHP scripts on behalf of a FastCGI client. FastCGI carries request metadata and input to an application process, and carries its response back. It is not HTTP on another port. Nginx does not interpret PHP code, and PHP-FPM is not a browser-facing web server. A PHP file sent as a static file can expose its source; only explicitly approved scripts should be routed for execution.
Browser --HTTP--> Nginx --FastCGI--> PHP-FPM workerBrowser <--HTTP-- Nginx <--FastCGI-- PHP-FPM worker/assets/site.css --> Nginx --> local static fileA first PHP response
<?phpheader('Content-Type: text/plain; charset=utf-8');header('Cache-Control: no-store');$name = $_GET['name'] ?? 'reader';if (!is_string($name) || !in_array($name, ['reader', 'Ada'], true)) { http_response_code(400); echo "Unknown name\n"; exit;}echo "Hello, {$name}!\n";The script returns plain text. With no name it produces Hello, reader!; with name=Ada it produces Hello, Ada!. Any other name or array value produces a 400 response. The lab tests those branches in PHP CLI, but headers and HTTP status must be checked through the web server. The script does not read secrets or a database.
Choose the transport and process pool
fastcgi_pass 127.0.0.1:19029;# Alternative for a same-host Unix socket, not a second directive:# fastcgi_pass unix:/run/bytemind-fpm/lab.sock;A Unix-domain socket uses a filesystem path instead of an IP address and port. Its directory and access permissions matter on Linux. For TCP, restrict the listener to loopback and allow only the local client; never publish an FPM port to the internet. FastCGI itself should not be treated as an authenticated public service. The lab uses TCP so two unprivileged processes can be started without creating a shared system socket directory.
[lab]listen = 127.0.0.1:19029listen.allowed_clients = 127.0.0.1pm = staticpm.max_children = 2security.limit_extensions = .phpA pool groups workers with its own settings. Static mode keeps a fixed worker count; dynamic mode adjusts the pool within limits; ondemand starts workers as needed. Two workers can handle at most two simultaneous PHP requests in this simple pool, while other requests may wait. This is a lab limit, not a production capacity recommendation. A static response need not occupy a PHP worker.
Practice and next step
Trace a request for /hello.php?name=Ada and one for /assets/site.css. Explain which process reads which file. Next, learn how the script filename and request metadata are selected.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
FastCGI and PHP-FPM architecture
Explain the request path from Nginx to PHP-FPM, and choose a bounded private FastCGI listener.
Which component runs PHP?
What protocol is used between Nginx and FPM?
Which listener belongs in the TCP lab?
What is the effect of two static FPM workers?
Why must a PHP file not be served as static text?