Nginx doesn’t run PHP. It hands every .php request to PHP-FPM over a Unix socket and waits for the answer, so most of the work in this stack is getting that handoff right. Which socket, which pool, which system user, and how many workers sit behind it? Get one of those wrong and you’ll see a 502, a bare “Access denied.” or a site that crawls the moment a few visitors arrive at once. If you searched “nginx php-fpm linux mint” because one of those is on your screen now, the last section maps each error to its fix.
This guide builds Nginx with PHP-FPM on Linux Mint 22 with a dedicated FPM pool per site, a server block that routes pretty URLs to index.php, a locked-down status page, worker limits sized from measured memory, and HTTPS from Let’s Encrypt. We reran the install, pool, server block and 502 steps in December 2026 on Linux Mint 22.3 with Nginx 1.24 and PHP 8.3 from the Ubuntu noble archive, and every other capture comes from identical builds three days earlier.
What you need
The core path needs very little, and only the HTTPS step depends on DNS.
- Linux Mint 22.x with a sudo user
- A domain whose A record points at the machine
- Ports 80 and 443 reachable from the internet
Our lab was the official Mint 22.3 image running under systemd on a cloud host with 2 vCPUs, 7.9 GB of RAM and a public IP, which is why the phpinfo kernel line further down mentions gcp. If you are still on Mint 21, do the Mint 21 to 22 upgrade first, because the package names and socket paths here assume the noble base. Skip it and none of the 8.3 paths below will exist on your system.
Several commands reuse the hostname, so export it once in your working shell and swap app.example.com for your own domain.
export DOMAIN=app.example.com
Open a new terminal later and the variable is gone, so re-run that line before you continue. Inside the two config files we write the hostname out literally, since Nginx and PHP-FPM don’t read your shell environment.
Install Nginx and PHP-FPM without Apache
Refresh the package index and apply pending updates first. Our fresh image had 145 upgradable packages, and installing PHP against stale libraries is a good way to chase phantom bugs later.
sudo apt update
sudo apt upgrade -y
Now install Nginx, PHP-FPM and the extensions most PHP apps expect. Notice that the bare php package is missing from this list. On Mint that metapackage pulls in apache2 and libapache2-mod-php8.3, and Apache then fights Nginx for port 80, so you get whichever server started first.
sudo apt install -y nginx php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-zip php-intl
apt resolved 26 new packages: PHP 8.3, Nginx and a few libraries, and nothing from Apache.
The following NEW packages will be installed:
libonig5 libzip4t64 nginx nginx-common php-common php-curl php-fpm php-gd
php-intl php-mbstring php-mysql php-xml php-zip php8.3-cli php8.3-common
php8.3-curl php8.3-fpm php8.3-gd php8.3-intl php8.3-mbstring php8.3-mysql
php8.3-opcache php8.3-readline php8.3-xml php8.3-zip psmisc
0 upgraded, 26 newly installed, 0 to remove and 0 not upgraded.
Confirm that nothing Apache came along, that both services are running and enabled at boot, and which PHP you got:
dpkg -l | grep -cE "apache2|libapache2"
systemctl is-active nginx php8.3-fpm
systemctl is-enabled nginx php8.3-fpm
php -v
A count of 0 is what you want from the first line. Both units report active and enabled, and the CLI reports the same PHP build that FPM runs.
0
active
active
enabled
enabled
PHP 8.3.6 (cli) (built: Nov 18 2026 23:42:07) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies
Here is the whole install check from our first lab run, three days before the December rerun. That run resolved 25 packages, one fewer than the rerun (no psmisc), with the same versions.

PHP 8.3 is what the noble archive ships and what Mint security updates patch. If an app needs a newer branch, or you want extensions this list does not cover, follow our guide to install a newer PHP on Linux Mint 22 and change every 8.3 path in this article to match the version you installed.
Check the PHP security patch level
Ubuntu backports fixes into the 8.3.6 package instead of bumping the version, so php -v alone won’t tell you whether you’re patched. The Debian changelog does.
dpkg-query -W php8.3-common
zcat /usr/share/doc/php8.3-common/changelog.Debian.gz | head -12
Our build was 0ubuntu0.24.04.14, and its top entry includes a fix for an XSS in the FPM status endpoint. That’s the page we expose to localhost later, and one more reason it never goes public.
php8.3-common 8.3.6-0ubuntu0.24.04.14
php8.3 (8.3.6-0ubuntu0.24.04.14) noble-security; urgency=medium
* SECURITY UPDATE: Information Leak
- debian/patches/CVE-2026-15353.patch: Out-of-bounds read on empty
SOAP-ENC:arraySize in ext/soap/php_encoding.c
- debian/patches/CVE-2026-129292.patch: FPM XSS within status
endpoint via user and script in sapi/fpm/fpm/fpm_status.c
- debian/patches/CVE-2026-128064.patch: Mixed case HTTPS and FTPS in
ext/standard/ftp_fopen_wrapper.c and
ext/standard/http_fopen_wrapper.c
- CVE-2026-15353
- CVE-2026-129292
If your version string is lower, run sudo apt upgrade -y again before going further, because an unpatched FPM is the one component every PHP site on the machine shares. Mint Update applies the same packages from the desktop if you prefer the GUI.
Inspect the default pool and socket
Before writing any config, look at what the package set up. PHP-FPM listens on a Unix socket in /run/php/, and the default www pool defines who owns it and how many workers it may start:
ls -l /run/php/
grep -E '^(user|group|listen|pm)' /etc/php/8.3/fpm/pool.d/www.conf
Two details in this output matter more than they look.
total 4
-rw-r--r-- 1 root root 5 Nov 29 15:48 php8.3-fpm.pid
srw-rw---- 1 www-data www-data 0 Nov 29 15:48 php8.3-fpm.sock
lrwxrwxrwx 1 root root 30 Nov 29 15:48 php-fpm.sock -> /etc/alternatives/php-fpm.sock
user = www-data
group = www-data
listen = /run/php/php8.3-fpm.sock
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
php-fpm.sockis an alternatives symlink. It follows whichever PHP version was installed last, so a later PHP install silently moves your site to another version. Point Nginx at a versioned socket instead.pm.max_children = 5caps the pool at five PHP requests in flight. We hit that limit with 20 concurrent clients in the tuning section.
The www pool also runs code as www-data, the same user Nginx runs as. One compromised site can then read the files of every other site on the box, database passwords in config files included. A pool per site fixes that, because each pool runs as its own user and can only read what that user owns.
Create a dedicated PHP-FPM pool for the site
Create a system user that owns the site’s code and runs its PHP, then the document root. The account has no shell and no home, so nobody logs in as it.
sudo useradd --system --no-create-home --shell /usr/sbin/nologin app
sudo mkdir -p /var/www/${DOMAIN}/public
sudo chown -R app:app /var/www/${DOMAIN}
Next, create the pool file. Its name only needs to end in .conf to be picked up from pool.d. The Mint 22.3 image we used ships nano but no full vim, so install vim first or use nano in the commands below.
sudo apt install -y vim
sudo vim /etc/php/8.3/fpm/pool.d/app.conf
Paste this pool definition. Workers run as app, but the socket belongs to www-data so Nginx can connect to it. The PHP limits are set with php_admin_value, which ini_set() in app code cannot override.
[app]
user = app
group = app
listen = /run/php/php8.3-fpm-app.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 500
pm.status_path = /fpm-status
ping.path = /fpm-ping
request_slowlog_timeout = 5s
slowlog = /var/log/php8.3-fpm-app-slow.log
php_admin_value[memory_limit] = 256M
php_admin_value[upload_max_filesize] = 64M
php_admin_value[post_max_size] = 64M
php_admin_value[error_log] = /var/log/php8.3-fpm-app-error.log
php_admin_flag[log_errors] = on
We start with the same five workers as the default pool on purpose, so the tuning section has a baseline to measure against. pm.max_requests = 500 recycles each worker after 500 requests, which caps the damage from a slow memory leak in app code. Every directive is documented in the PHP-FPM configuration reference.
Test the config before restarting. A typo in any pool file stops the whole service, every other site included.
sudo php-fpm8.3 -t
sudo systemctl restart php8.3-fpm
ls -l /run/php/*.sock
ps -o user,pid,cmd -C php-fpm8.3
The new socket shows up next to the default one, and the process list proves the split: a root master, two workers running as app and two as www-data.
[02-Dec-2026 15:19:06] NOTICE: configuration file /etc/php/8.3/fpm/php-fpm.conf test is successful
srw-rw---- 1 www-data www-data 0 Dec 2 15:19 /run/php/php8.3-fpm-app.sock
srw-rw---- 1 www-data www-data 0 Dec 2 15:19 /run/php/php8.3-fpm.sock
lrwxrwxrwx 1 root root 30 Dec 2 15:18 /run/php/php-fpm.sock -> /etc/alternatives/php-fpm.sock
USER PID CMD
root 16869 php-fpm: master process (/etc/php/8.3/fpm/php-fpm.conf)
app 16870 php-fpm: pool app
app 16871 php-fpm: pool app
www-data 16872 php-fpm: pool www
www-data 16873 php-fpm: pool www
The two pools now run side by side under different users. The terminal below is from the first run, so its PIDs differ from the block above.

For a second site, repeat the user, directory and pool file with a new name and socket path. Each site then gets its own worker limit and its own file permissions, so a traffic spike on one site cannot starve the others of workers. The cost is a few idle processes per pool, roughly 17 MB each on this box.
Write the Nginx server block
The Ubuntu Nginx package keeps sites in sites-available and enables them with a symlink in sites-enabled. Create the site file.
sudo vim /etc/nginx/sites-available/${DOMAIN}.conf
Paste the server block below and replace app.example.com with your domain in server_name, root and the two log paths:
server {
listen 80;
listen [::]:80;
server_name app.example.com;
root /var/www/app.example.com/public;
index index.php index.html;
client_max_body_size 64M;
access_log /var/log/nginx/app.example.com.access.log;
error_log /var/log/nginx/app.example.com.error.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm-app.sock;
}
location ~ ^/(fpm-status|fpm-ping)$ {
allow 127.0.0.1;
allow ::1;
deny all;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php8.3-fpm-app.sock;
}
location ~ /\.(?!well-known) {
deny all;
}
}
Each location does one job. The try_files line serves real files directly and sends everything else to index.php, which is how WordPress, Laravel and most frameworks route pretty URLs. The \.php$ block uses the stock snippets/fastcgi-php.conf, which already returns 404 for PHP files that do not exist, and passes to the versioned pool socket. The status block answers only to localhost. The last block hides dotfiles such as .env and .git, but leaves .well-known open for certificate challenges. client_max_body_size matches the 64M upload limit in the pool, because the Nginx default is 1 MB and would refuse large uploads before PHP ever saw them.
Enable the site, test the syntax and reload.
sudo ln -s /etc/nginx/sites-available/${DOMAIN}.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Only reload after nginx -t reports success, since a reload with a broken file is refused and the old config keeps serving.
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Leave the stock default site enabled for now. It only answers requests that match no other server_name, so it does not interfere with this site, and it gives you a quick way to tell a DNS mistake (you land on the Nginx welcome page) from a PHP mistake.
Open HTTP and HTTPS in the firewall
Mint ships ufw, and the Nginx package registers application profiles for it. If ufw is active on your machine, allow both ports in one rule.
sudo ufw app list
sudo ufw allow 'Nginx Full'
“Nginx Full” covers 80 and 443, and the rule goes in for IPv4 and IPv6.
Available applications:
Nginx Full
Nginx HTTP
Nginx HTTPS
Rules updated
Rules updated (v6)
On a cloud VM, the firewall or security group of the provider needs the same two ports open as well, or the certificate challenge below will time out. Opening 443 before a certificate exists is harmless, because nothing listens on it until Certbot adds the TLS server block.
Test PHP with phpinfo and a front controller
Write a phpinfo page as the app user, so the file has the same owner your real code will have, then pull the lines that prove the request went through the right pool.
echo '<?php phpinfo();' | sudo -u app tee /var/www/${DOMAIN}/public/info.php >/dev/null
curl -s http://${DOMAIN}/info.php | sed 's/<[^>]*>/ /g' | grep -E '^ *(Server API|Loaded Configuration File|memory_limit|upload_max_filesize|post_max_size) ' | tr -s ' '
FPM/FastCGI confirms Nginx handed the request to PHP-FPM, and the 256M and 64M values come from the php_admin_value lines in the pool, not from php.ini. That is how you know the request hit app and not www, because the stock php.ini on Mint sets them to 128M, 8M and 2M.
Server API FPM/FastCGI
Loaded Configuration File /etc/php/8.3/fpm/php.ini
memory_limit 256M 256M
post_max_size 64M 64M
upload_max_filesize 64M 64M
Server API (SAPI) Abstraction Layer Andi Gutmans, Shane Caraveo, Zeev Suraski
Ignore the last line, which the grep picks up from the credits table. The same page in a browser, here after the HTTPS step, shows the full module list your apps can count on.

phpinfo tells an attacker your exact versions and paths, so delete info.php once you have looked (we do it at the end). Next, test the routing with a one-line front controller that prints the requested URI, the SAPI and the user PHP runs as.
echo '<?php echo $_SERVER["REQUEST_URI"], " -> ", PHP_SAPI, " as ", posix_getpwuid(posix_geteuid())["name"], PHP_EOL;' | sudo -u app tee /var/www/${DOMAIN}/public/index.php >/dev/null
curl -s http://${DOMAIN}/hello-world/
curl -s -o /dev/null -w '%{http_code}\n' http://${DOMAIN}/.env
/hello-world/ doesn’t exist on disk, yet index.php answered it, running as app. The dotfile request gets a 403 from the deny rule.
/hello-world/ -> fpm-fcgi as app
403
The terminal view puts the config test and the routing test together.

That’s the whole request path working, from Nginx through the socket to a worker running as the right user. From here the document root is ready for a real app, for example WordPress on Linux Mint 22, which drops straight into this server block because its permalinks rely on the same try_files fallback. Deploy the code as app so the workers can read it.
Read the PHP-FPM status page
The pm.status_path setting gives you a live count of busy and idle workers. Query it through Nginx from the server itself, sending the Host header of the site so the right server block answers.
curl -s -H "Host: ${DOMAIN}" http://127.0.0.1/fpm-status
curl -s -o /dev/null -w '%{http_code}\n' http://${DOMAIN}/fpm-status
From localhost you get the counters, and from the public address a 403.
pool: app
process manager: dynamic
start time: 29/Nov/2026:15:49:49 +0000
start since: 61
accepted conn: 6
listen queue: 0
max listen queue: 0
listen queue len: 0
idle processes: 1
active processes: 1
total processes: 2
max active processes: 1
max children reached: 0
slow requests: 0
403
Both answers side by side show the access rule doing its job.

Two counters deserve a place in your monitoring. max children reached counts how often the pool ran out of workers, and listen queue shows requests waiting for one. Anything above zero on either means visitors are waiting, which is exactly what the next section provokes on purpose.
Size pm.max_children from measured memory
Five workers is a safe default for a small VPS and far too few for most real sites. To see the limit bite, we put a test page in the document root that allocates 30 MB and sleeps for 200 ms, roughly a heavy CMS page, and hit it with ApacheBench. The ab tool comes from apache2-utils, which installs only the client tools, not the Apache server.
sudo apt install -y apache2-utils
echo '<?php $buf = str_repeat("x", 30 * 1024 * 1024); usleep(200000); echo strlen($buf), PHP_EOL;' | sudo -u app tee /var/www/${DOMAIN}/public/work.php >/dev/null
ab -q -n 400 -c 20 http://${DOMAIN}/work.php | grep -E 'Requests per second|Time per request|Failed requests| 95%'
Twenty concurrent clients against five workers means fifteen of them always wait in line.
Failed requests: 0
Requests per second: 20.27 [#/sec] (mean)
Time per request: 986.741 [ms] (mean)
Time per request: 49.337 [ms] (mean, across all concurrent requests)
95% 1273
Nothing failed, and that is the trap. The site stays up and just gets slow, so uptime checks stay green while visitors wait a full second per page. The only loud signal is in the FPM log, so check it and the status counters.
sudo grep max_children /var/log/php8.3-fpm.log | tail -2
curl -s -H "Host: ${DOMAIN}" http://127.0.0.1/fpm-status | grep -E 'listen queue|max children|max active'
All five workers were busy and the pool hit its ceiling.
[29-Nov-2026 15:51:15] WARNING: [pool app] server reached pm.max_children setting (5), consider raising it
listen queue: 0
max listen queue: 0
listen queue len: 0
max active processes: 5
max children reached: 1
This is the baseline run in full, warning included.

Don’t raise the number by guesswork. Measure what one worker costs, then divide the RAM you can spare by that figure. The full status page reports the peak PHP memory of every worker, and ps gives the resident size of the processes.
curl -s -H "Host: ${DOMAIN}" 'http://127.0.0.1/fpm-status?full' | grep -E 'last request memory' | sort | uniq -c
ps -o rss= -u app | awk '{s+=$1; n++} END {printf "%d workers, %.1f MB average RSS\n", n, s/n/1024}'
free -m | head -2
The heaviest request peaked at 33,558,528 bytes (32 MB), an idle worker holds about 17.5 MB, and the box has 7,934 MB in total.
1 last request memory: 0
1 last request memory: 2097152
1 last request memory: 33558528
3 workers, 17.5 MB average RSS
total used free shared buff/cache available
Mem: 7934 702 3627 3 3914 7231
So a busy worker costs about 50 MB here, the idle footprint plus the peak of the request. Leave 1.5 to 2 GB for the OS, Nginx and a database, and memory alone would allow over a hundred workers. CPU says otherwise. On 2 vCPUs, extra workers past a few dozen just queue for the processor, so we capped the pool at 40. That’s 2 GB in the worst case, with headroom for a traffic spike. Change the four pm values in the pool file, or apply them with sed.
sudo sed -i -e 's/^pm.max_children = .*/pm.max_children = 40/' -e 's/^pm.start_servers = .*/pm.start_servers = 8/' -e 's/^pm.min_spare_servers = .*/pm.min_spare_servers = 4/' -e 's/^pm.max_spare_servers = .*/pm.max_spare_servers = 12/' /etc/php/8.3/fpm/pool.d/app.conf
sudo php-fpm8.3 -t
sudo systemctl reload php8.3-fpm
A reload restarts the workers, and with the stock process_control_timeout = 0 a worker still busy with a request is killed rather than allowed to finish, so make pool changes in a quiet moment. We re-ran the same 400-request test against the tuned pool, then the status query (filtered for total processes this time) and the ps one-liner.
Failed requests: 0
Requests per second: 40.68 [#/sec] (mean)
Time per request: 491.672 [ms] (mean)
Time per request: 24.584 [ms] (mean, across all concurrent requests)
95% 629
total processes: 24
max active processes: 24
max children reached: 0
22 workers, 17.6 MB average RSS
The tuned run, from the sed edit to the worker count, looked like this.

Side by side, the change roughly doubled throughput and halved latency on the same hardware.
| Pool setting | Requests/s | Mean latency | 95th percentile | max children reached |
|---|---|---|---|---|
| Default (5 / 2 / 1 / 3) | 20.27 | 987 ms | 1,273 ms | 1 |
| Tuned (40 / 8 / 4 / 12) | 40.68 | 492 ms | 629 ms | 0 |
The pool used 24 of its 40 slots at 20 concurrent clients, so the cap is above real demand without being reckless. The gain flattened at about 2x, well short of what 20 sleeping workers could serve in theory, because ab, Nginx and two dozen PHP workers all shared the same two vCPUs. Run the same test on your own hardware before settling on a number, since the useful ceiling depends on how much of each request is CPU work and how much is waiting.
Add HTTPS with Let’s Encrypt
The Certbot Nginx plugin uses the HTTP-01 challenge. Let’s Encrypt fetches a token over port 80, so the domain must resolve to this machine and port 80 must be reachable from the internet. Install the plugin and request the certificate.
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d ${DOMAIN} --non-interactive --agree-tos --redirect --register-unsafely-without-email
We skipped the email because Let’s Encrypt stopped sending expiry reminders in 2025, so the address no longer buys you a warning. Pass -m [email protected] instead only if you want to join the ISRG update mailing lists. Certbot issued the certificate and wrote it into the server block in one run.
Account registered.
Requesting a certificate for app.example.com
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/app.example.com/fullchain.pem
Key is saved at: /etc/letsencrypt/live/app.example.com/privkey.pem
This certificate expires on 2027-02-27.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
Deploying certificate
Successfully deployed certificate for app.example.com to /etc/nginx/sites-enabled/app.example.com.conf
Congratulations! You have successfully enabled HTTPS on https://app.example.com
The whole issuance took a few seconds on our lab host.

Certbot moved the original server block to port 443 and added a second one on port 80 whose only job is the redirect. Grep the file to see what it changed.
grep -n -E "listen|ssl_|managed by Certbot|return 301" /etc/nginx/sites-available/${DOMAIN}.conf
Every line tagged managed by Certbot is rewritten on renewal, so keep your own edits outside them.
34: listen [::]:443 ssl ipv6only=on; # managed by Certbot
35: listen 443 ssl; # managed by Certbot
36: ssl_certificate /etc/letsencrypt/live/app.example.com/fullchain.pem; # managed by Certbot
37: ssl_certificate_key /etc/letsencrypt/live/app.example.com/privkey.pem; # managed by Certbot
38: include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
39: ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
44: return 301 https://$host$request_uri;
45: } # managed by Certbot
48: listen 80;
49: listen [::]:80;
51: return 404; # managed by Certbot
Check the redirect, the PHP route over TLS, the renewal timer and a dry-run renewal.
curl -sI http://${DOMAIN}/ | head -3
curl -s https://${DOMAIN}/hello-world/
systemctl list-timers certbot.timer --no-pager | head -2
sudo certbot renew --dry-run 2>&1 | tail -3
Plain HTTP now answers with a 301, PHP still runs as app behind TLS, and the systemd timer will renew the certificate well before it expires.
HTTP/1.1 301 Moved Permanently
Server: nginx/1.24.0 (Ubuntu)
Date: Sun, 29 Nov 2026 15:52:52 GMT
/hello-world/ -> fpm-fcgi as app
NEXT LEFT LAST PASSED UNIT ACTIVATES
Mon 2026-11-30 01:13:58 UTC 9h - - certbot.timer certbot.service
Congratulations, all simulated renewals succeeded:
/etc/letsencrypt/live/app.example.com/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
All four checks passed in one go.

Now remove the two test files. phpinfo leaks versions and paths, and the load-test page burns 30 MB per hit, which makes it a free denial of service for anyone who finds it.
sudo rm /var/www/${DOMAIN}/public/info.php /var/www/${DOMAIN}/public/work.php
A request for /info.php now returns 404 from the PHP location block.
Use DNS-01 when port 80 is closed
A machine on a home network, or behind a firewall you cannot open, cannot pass HTTP-01. The alternative is the DNS-01 challenge, where you prove control of the domain with a TXT record instead of a web request. The manual mode of Certbot prints the record for you to create, but a certificate issued that way will not renew unattended, so use the DNS plugin for your provider instead, such as python3-certbot-dns-cloudflare from the Ubuntu archive. The plugin reads an API token from a credentials file you pass with --dns-cloudflare-credentials. Run it as the authenticator with the Nginx plugin as the installer (-a dns-cloudflare -i nginx --redirect), and Certbot writes the same 443 server block and redirect that the HTTP-01 run produced above.
Fix the errors this stack throws
We broke the lab on purpose to capture each of these. The browser error is rarely enough, so the per-site error log is always the first place to look, with sudo tail /var/log/nginx/${DOMAIN}.error.log.
502 Bad Gateway: “connect() to unix:/run/php/php8.2-fpm.sock failed (2: No such file or directory)”
Nginx is pointing at a socket that does not exist, usually because a config was copied from a guide written for another PHP version. We reproduced it by switching fastcgi_pass to a php8.2 socket, then checked the response, the per-site log and the socket directory. Our December rerun had no certificate yet, so plain HTTP reached PHP. Behind Certbot’s redirect, port 80 answers 301 instead, so send the same curl -sI to https://${DOMAIN}/.
sudo sed -i "s|php8.3-fpm-app.sock;|php8.2-fpm.sock;|" /etc/nginx/sites-available/${DOMAIN}.conf
sudo nginx -t
sudo systemctl reload nginx
curl -sI -H "Host: ${DOMAIN}" http://127.0.0.1/ | head -2
sudo tail -1 /var/log/nginx/${DOMAIN}.error.log
ls /run/php/
Notice that nginx -t passed. It checks syntax, not whether the socket exists, so the break only shows up on the first request.
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
HTTP/1.1 502 Bad Gateway
Server: nginx/1.24.0 (Ubuntu)
2026/12/02 15:19:33 [crit] 16970#16970: *5 connect() to unix:/run/php/php8.2-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: app.example.com, request: "HEAD / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.2-fpm.sock:", host: "app.example.com"
php8.3-fpm-app.sock
php8.3-fpm.pid
php8.3-fpm.sock
php-fpm.sock
The sed changed both fastcgi_pass lines, the PHP location and the status location, so put the real socket back in both before going on.
sudo sed -i "s|php8.2-fpm.sock;|php8.3-fpm-app.sock;|" /etc/nginx/sites-available/${DOMAIN}.conf
sudo nginx -t 2>&1 | tail -1
sudo systemctl reload nginx
curl -sI -H "Host: ${DOMAIN}" http://127.0.0.1/ | head -1
The response went straight back to normal.
nginx: configuration file /etc/nginx/nginx.conf test is successful
HTTP/1.1 200 OK
On a real site, run ls -l /run/php/, copy the exact socket name into fastcgi_pass, then sudo nginx -t and reload. If the socket is missing entirely, PHP-FPM itself isn’t running, and sudo php-fpm8.3 -t shows which pool file broke it. A “(13: Permission denied)” variant of the same line means the Nginx user can’t open the socket, so check listen.owner, listen.group and listen.mode in the pool.
“Access denied.” and “Unable to open primary script”
The browser gets a 403 with the bare text “Access denied.” and nothing else. The log explains it.
2026/11/29 15:56:06 [error] 34631#34631: *1744 FastCGI sent in stderr: "PHP message: PHP Warning: PHP Request Startup: Failed to open stream: Permission denied in Unknown on line 0; Unable to open primary script: /var/www/app.example.com/public/private.php (Permission denied)" while reading response header from upstream, client: 203.0.113.10, server: app.example.com, request: "GET /private.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.3-fpm-app.sock:", host: "app.example.com"
We caused it by creating a file as root with mode 600, which the app pool user can’t read. Files deployed with sudo cp or extracted as root do the same. Fix the owner with sudo chown -R app:app /var/www/${DOMAIN}. If you see this error on a fresh site, check that root in the server block and the path in the message actually match.
413 Request Entity Too Large: “client intended to send too large body”
Nginx rejects the upload before PHP sees it, so the PHP limits don’t matter here. A 70 MB POST against our 64M cap produced this log line.
2026/11/29 15:56:11 [error] 34632#34632: *1746 client intended to send too large body: 73400320 bytes, client: 203.0.113.10, server: app.example.com, request: "POST / HTTP/1.1", host: "app.example.com"
You’ll need to raise three limits together, because each layer checks the upload on its own.
client_max_body_sizein the server blockpost_max_sizein the pool fileupload_max_filesizein the pool file
Raising only one of the three just moves the error somewhere else. If you raise the Nginx value alone, the upload reaches PHP, and a body over post_max_size arrives with empty $_POST and $_FILES arrays instead of a clear 413, which is much harder to debug. Reload both services after the change so they pick it up.
“server reached pm.max_children setting (5), consider raising it”
This warning in /var/log/php8.3-fpm.log means requests queued for a worker. Size the pool from memory as shown above rather than doubling the number blindly. If the warning comes back after tuning, look at the slow log at /var/log/php8.3-fpm-app-slow.log. Workers stuck on a slow query or API call fill any pool, however large it is.
The same pool and server block layout works on other distributions with different paths. The RHEL family names the service php-fpm and runs it as apache, which our Install PHP 8.4 on Rocky Linux 10 / 9 and AlmaLinux 10 / 9 guide covers. If you’d rather stay on Apache, How To Install PHP with Apache on Ubuntu and Debian has that stack, and our list of Nginx and Apache books goes deeper into both servers.