All Tools View Categories About Contact Privacy

Nginx PHP-FPM Config Generator

Wire nginx to PHP-FPM for dynamic PHP sites over Unix socket or TCP.

Runs entirely in your browser - nothing is uploaded and no cloud connection is made.
Your PHP-FPM server block will appear here.
-
lines
-
blocks
-
locations

About Nginx PHP-FPM Config Generator

Serving PHP through nginx means handing requests to PHP-FPM over FastCGI, and a small mistake breaks the whole site: a missing fastcgi_pass so PHP files download instead of execute, a socket path that points at a pool that does not exist, a regex location that accidentally matches static files, or a read timeout so short that long scripts get cut off. The Nginx PHP-FPM Config Generator builds a correct server block that routes PHP to FPM over a Unix socket or TCP and validates the result before you copy it.

At the heart of the configuration are a handful of directives. fastcgi_pass forwards matching requests to the PHP-FPM upstream, given as a Unix socket or host:port. include (fastcgi-php.conf) loads the standard FastCGI parameter set such as SCRIPT_FILENAME. location php matches PHP requests only so static assets bypass the interpreter. try_files resolves pretty URLs by falling back to index.php with the query string. root sets the absolute directory nginx and FPM read PHP files from. fastcgi_read_timeout limits how long nginx waits for PHP to respond before giving up. index names the PHP entry file used for directory requests. Together they shape how the server behaves, and the tool assembles them in the right context so the result is valid on the first try.

Common mistakes are easy to make. Omitting fastcgi_pass makes nginx serve PHP source as a download; the generator always emits it. Pointing the socket at a non-absolute path or a bad host:port fails at reload, so the tool validates both forms. Routing every file to FPM is unsafe; the regex location restricts FastCGI to php requests only. The generator anticipates each of these and either sets a safe default or rejects the input with a clear message before anything is written to your clipboard.

Validation is strict because small configuration errors fail in subtle ways. Every input is checked for plausibility, and after the block is assembled it is re-parsed by a built-in tokenizer so unbalanced braces, missing semicolons or stray characters cannot reach your clipboard. Stat cards report line and block counts, and copy, download and print exports are one click away. Everything runs in your browser; nothing you type is transmitted to any server.

In practice this block drops into any standard nginx install. Save the output as a file under /etc/nginx/conf.d/ (or sites-available with a symlink), run nginx -t to confirm the syntax, then reload with nginx -s reload. Because the generator emits a single, self-contained server block with no hidden dependencies, it composes cleanly with your existing caching, logging and security configuration without directive collisions.

Beyond producing correct config, the tool is a reference you can read back and learn from. Each control maps to a real nginx directive, the sample button shows a complete working block in seconds, and clearing the form resets every field to its safe default. Standardising on a generator like this removes per-developer variation, keeps your configuration readable, and gives you a repeatable, auditable setup that passes nginx -t on the first try.

When something looks wrong in production, the first move is always to re-run nginx -t and inspect /var/log/nginx/error.log; most failures surface there with a line number. The access log records every request, so a sudden spike or a wall of 499 responses points straight at backend or timeout problems the generator helps you avoid in the first place.

This server block is designed to sit alongside - not fight - your other configuration. Because it declares its own server_name and a single, self-contained set of directives, you can drop it into conf.d without worrying about collisions with global caching, logging or security snippets that live elsewhere in the nginx tree.

For a production site, pair this block with TLS termination: serve on 80 for the redirect or health checks, and place the encrypted listener (or a front-end load balancer / CDN) in front so clients always speak HTTPS. The generator keeps that boundary clean so the two layers compose instead of overlapping.

If a change ever needs to be undone, the output is plain text you control: delete the file from conf.d, re-run nginx -t, and reload. There is no database and no hidden state, so rolling back is as simple as restoring the previous version from version control or your own backup.

Performance and correctness both benefit from explicit configuration. Defaults baked into the generator reflect current best practice rather than decades-old forum snippets, so the block you ship today will not surprise you with deprecated directives or insecure fallbacks six months from now.

Features

  • fastcgi_pass - forwards matching requests to the PHP-FPM upstream, given as a Unix socket or host:port.
  • include (fastcgi-php.conf) - loads the standard FastCGI parameter set such as SCRIPT_FILENAME.
  • location php - matches PHP requests only so static assets bypass the interpreter.
  • try_files - resolves pretty URLs by falling back to index.php with the query string.
  • root - sets the absolute directory nginx and FPM read PHP files from.
  • fastcgi_read_timeout - limits how long nginx waits for PHP to respond before giving up.
  • index - names the PHP entry file used for directory requests.
  • Self-verifying output re-parsed before display.
  • Copy, Download and Print exports.
  • Load-sample button fills realistic values.
  • Statistics cards for quick checks.
  • Runs entirely in your browser - nothing uploaded.

How to Use

  1. Enter the public domain the block serves.
  2. Set the absolute document root where PHP files live.
  3. Enter the PHP-FPM upstream as unix:/path/sock or host:port.
  4. Set the index file, usually index.php.
  5. Choose a FastCGI read timeout in seconds.
  6. Click Generate (or Load sample) and review the block.
  7. Place it in conf.d, run nginx -t, then reload.

Examples

Example 1 - Unix socket PHP served through the local PHP-FPM Unix socket - the common single-host setup.

Example 2 - TCP upstream fastcgi_pass to 127.0.0.1:9000 when FPM listens on TCP.

Example 3 - Pretty URLs try_files falls back to index.php so permalinks work.

Example 4 - Bad domain rejected an invalid domain is reported before generation.

Example 5 - Bad socket rejected a socket without host:port or an absolute unix path is caught.

Benefits

  • Correct FastCGI routing to PHP-FPM every time.
  • Unix socket and TCP upstreams both supported.
  • PHP-only regex location keeps static files fast and safe.
  • Validated socket/host so reloads never fail.
  • Self-checked output re-parsed before display.
  • Private: everything runs in your browser.

Frequently Asked Questions

Unix socket or TCP?
Unix sockets avoid network overhead and are common on the same host; TCP (host:port) is handy when PHP-FPM runs in another container or host.
What is fastcgi-php.conf?
It is the standard Debian/Ubuntu snippet that sets SCRIPT_FILENAME and other FastCGI parameters the PHP interpreter expects.
Why the regex on php?
It routes only PHP requests to FPM while static files are served directly, which is both faster and safer.
My PHP files download instead of run
That means nginx is not passing php to fastcgi; confirm the location block and fastcgi_pass are present and that fastcgi-php.conf is included.
How do I pick the socket path?
It matches your PHP-FPM pool (often /run/php/php8.2-fpm.sock); the generator only references it, it does not create it.
What is fastcgi_read_timeout?
It caps how long nginx waits for PHP to return, protecting you from a hung script holding the connection.
Is the output validated?
Yes - the block is re-parsed by a built-in tokenizer before display.
Is anything uploaded?
No. All generation runs locally in your browser.