About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
When a PHP page shows the plain text "File not found." and PHP-FPM logs "Primary script unknown" (at debug level only), nginx handed the request to PHP-FPM, but the file path that nginx sent in SCRIPT_FILENAME did not lead to a script PHP-FPM could use. The fault is in that path: it is missing, wrong, or points somewhere PHP-FPM cannot see. The nginx 404 page is a different problem and has different wording.
What the symptom means
PHP-FPM learns which script to run from the SCRIPT_FILENAME parameter that nginx passes. The nginx documentation says: "The SCRIPT_FILENAME parameter is used in PHP for determining the script name". The nginx beginner's guide shows the usual form: fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;. $document_root is the "root or alias directive's value for the current request" and $fastcgi_script_name is the request URI, or, for a URI ending in a slash, the URI plus the fastcgi_index file name.
The PHP source (branches 7.4, 8.0 and 8.4) shows three different outcomes in sapi/fpm/fpm/fpm_main.c:
| What the visitor sees | HTTP status | What happened in PHP-FPM |
|---|---|---|
File not found. |
404 | No script path was available. FPM logs Primary script unknown, but only at debug level |
No input file specified. |
404 | A path was given but PHP could not open it, and the cause was not a permission error |
Access denied. |
403 | The file's extension is not allowed by security.limit_extensions, or the open failed with a permission error |
The first row is the one in the title. In the source, init_request_info leaves the path empty when SCRIPT_FILENAME is absent. With cgi.fix_pathinfo on (the manual lists its default as "1"), FPM also tries to work out the script by stripping trailing path pieces until it finds a regular file. If it strips everything and finds none, the source comment says "we will fail, badly" and the script name is cleared. Either way the result is "File not found." with a 404.
security.limit_extensions defaults to .php .phar, and the manual says it "Limits the extensions of the main script FPM will allow to parse" and "can prevent configuration mistakes on the web server side".
Likely causes
| Cause | What you see | How to confirm |
|---|---|---|
SCRIPT_FILENAME is not passed at all |
File not found. for every PHP file |
nginx -T shows no fastcgi_param SCRIPT_FILENAME in effect for that location |
A fastcgi_param at location level hides those set higher up |
The same, after someone added one unrelated fastcgi_param |
The nginx page: parameters are inherited "if and only if there are no fastcgi_param directives defined on the current level" |
root is wrong or missing in the matching location |
The path in the log or debug output does not exist | The root in effect gives a path that ls cannot find; the root default is html |
| PHP-FPM sees a different file system | The file exists for nginx and not for PHP-FPM | The pool uses chroot, or PHP-FPM runs in another container or host with a different path |
| The script path exists but PHP-FPM cannot read it | No input file specified. or Access denied. |
ls -l and the PHP-FPM log line Unable to open primary script |
| The extension is not on the allow list | Access denied. for an unusual extension |
security.limit_extensions in the pool file |
Prove the cause before changing anything
All of these are read-only unless marked.
1. See the exact response.
curl -s https://app.example.com/index.php
The body is the plain text from PHP-FPM. File not found. points at a missing or empty path, No input file specified. at a path that does not open, and Access denied. at an extension or permission problem.
2. Read the nginx error log. The nginx default is error_log logs/error.log error;. The nginx source logs backend error-stream text as FastCGI sent in stderr: "...". Neither nginx nor PHP documents how the PHP-FPM debug line reaches nginx's error log, so do not rely on seeing "Primary script unknown" there; the visitor's text above is the dependable signal.
3. Read the configuration the site really uses.
nginx -T
Find the location that handles PHP. Note its root (or the one inherited from server), every fastcgi_param in effect, and the fastcgi_pass target.
4. Work out the path and look for it. Join the root and the URI the way $document_root$fastcgi_script_name does. For root /var/www/app/public; and the request /index.php, the path is /var/www/app/public/index.php.
ls -l /var/www/app/public/index.php
5. Check whether PHP-FPM runs in a chroot or elsewhere. Read the pool file. The PHP manual says of chroot: "Chroot to this directory at the start. This value must be defined as an absolute path. When this value is not set, chroot is not used." If it is set, FPM resolves SCRIPT_FILENAME relative to that directory's view of the file system. If FPM runs in another container or on another host, the path must exist there with the same name.
6. See FPM's own message, if you need it. Read the pool's security.limit_extensions too. The FPM global log_level has the default notice, so the debug line is not written until you raise it. Save the file first:
cp -p /etc/php/8.4/fpm/php-fpm.conf /root/php-fpm.conf.2026-11-20
php-fpm -t
Disruptive step: reloading FPM in the next step asks the service to read its configuration again, and the PHP manual does not describe what happens to requests in flight during a reload. Debug logging is verbose and slows a busy server. Use it briefly.
Set log_level = debug, test again with php-fpm -t ("Test FPM configuration and exit" in the PHP source), then reload the service with systemctl reload php8.4-fpm.
To back out, restore the saved file under the name you saved it, test, and reload:
cp -p /root/php-fpm.conf.2026-11-20 /etc/php/8.4/fpm/php-fpm.conf
php-fpm -t
systemctl reload php8.4-fpm
The paths and the unit name are examples. They differ between systems.
Fix
Disruptive step: nginx changes affect live traffic as soon as the reload completes. Save the file outside any directory your configuration includes by wildcard:
cp -p /etc/nginx/conf.d/app.example.com.conf /root/app.example.com.conf.2026-11-20
Then make the edit described below, test it, and only then reload:
nginx -t
nginx -s reload
The nginx manual says -t checks the syntax and "tries to open files referred in the configuration", and reload starts "the new worker process with a new configuration". To back out, restore the copy under the name you saved, test and reload again:
cp -p /root/app.example.com.conf.2026-11-20 /etc/nginx/conf.d/app.example.com.conf
nginx -t
nginx -s reload
Pass SCRIPT_FILENAME
In the PHP location, add or correct:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
If you use fastcgi_split_path_info, the nginx page notes that "$fastcgi_script_name variable equals the value of the first capture", and its example is fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name; with fastcgi_param PATH_INFO $fastcgi_path_info;. Remember that a fastcgi_param at location level means none of the server-level ones are inherited, so repeat every parameter PHP needs there, including QUERY_STRING.
Correct the root
Set root at server level so that every location, including the PHP one, shares it. The nginx documentation shows root /data/w3; placed in a location when only that location needs it. The default is html, which may not be your site's real path.
Make the path the same on both sides
If PHP-FPM is in a chroot, nginx must send the path as FPM sees it, which means a different prefix in SCRIPT_FILENAME from the root. The nginx page shows a fixed prefix in its own example, fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;.
Risk: a path that is correct for nginx but not for FPM causes the same "File not found" error, so test one PHP URL straight after the reload.
In containers, mount the web root at the same path in both, or set the prefix in fastcgi_param to match.
Permissions and extensions
For No input file specified. or Access denied., check that the pool's user can read the file and search every directory above it (namei -l shows each part). For an unusual extension, the manual says "You should only limit FPM to .php extensions", so change security.limit_extensions only when you understand why the extension is used.
Example (illustrative): On web01, app.example.com returns File not found. for every .php URL after an administrator adds fastcgi_param APP_ENV production; inside the PHP location. Before this change the location inherited from the server block a single SCRIPT_FILENAME line (the only fastcgi_param there); the new fastcgi_param on the location hides it, because the nginx page says parameters are inherited "if and only if there are no fastcgi_param directives defined on the current level". nginx -T shows no SCRIPT_FILENAME in that location. The administrator saves the file to /root, adds fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; to the location, runs nginx -t, then nginx -s reload. The page loads.
Confirm the fix
curl -s https://app.example.com/index.phpreturns the application's output, not the plain text from PHP-FPM.- A URL with extra path information (if your application uses it) still works.
- No new
Unable to open primary scriptlines appear in the PHP-FPM log, and no new errors in the nginx log. - If you raised
log_level, set it back and reload once more, then check the log stays quiet.
What to watch afterwards
- After any edit to a
locationthat usesfastcgi_pass, request one PHP URL. A change at the wrong level breaks every PHP page at once. - After a deployment change that moves or symlinks the web root, or moves PHP into a container, repeat the path check in step 4.
- Keep one shared snippet for the FastCGI parameters, so locations do not drift apart.
- Watch the PHP-FPM log for
Unable to open primary scriptlines.
Read next
Related articles you may want next.
- Troubleshootingnginx 502 Bad Gateway: connect() failed (111: Connection refused) while connecting to upstreamnginx 502 Bad Gateway with connect() failed (111: Connection refused) while connecting to upstream. Match the error log line to the cause and fix it.Read article
- PerformancePHP-FPM Has Reached pm.max_children: Measure Queueing Before Adding WorkersSeparate long-running requests from insufficient concurrency and size workers against measured memory and dependency limits.Read article
- Troubleshootingnginx 403 Forbidden: "directory index of ... is forbidden" and "Permission denied" in the error lognginx 403 with 'directory index of ... is forbidden' or '(13: Permission denied)': read the error log line, then fix index, permissions or SELinux.Read article
Risks and limits
- These commands have not been run or lab-tested.
- The response text is from PHP source on three branches. Other versions may differ. The source does not show how a log line reaches nginx's error log.
- The
cgi.fix_pathinfobehaviour described is read from the source ofinit_request_info. It has not been tested here. - The manual's default value for
cgi.fix_pathinfois "1", and the manual's Changeable column for it showsINI_SYSTEM. - Container networking, shared file systems and chroot layouts vary. The paths and unit names above are examples.
Sources
- nginx: ngx_http_fastcgi_module — nginx documentation, no date shown, accessed 20 November 2026
- nginx: ngx_http_core_module — nginx documentation, no date shown, accessed 20 November 2026
- nginx: Beginner's Guide — nginx documentation, no date shown, accessed 20 November 2026
- nginx: core functionality (error_log) — nginx documentation, no date shown, accessed 20 November 2026
- nginx: command-line parameters — nginx documentation, no date shown, accessed 20 November 2026
- nginx 1.30.6 source: ngx_http_fastcgi_module.c — nginx project, tag release-1.30.6, no date shown, accessed 20 November 2026
- nginx: download — nginx.org, no date shown, lists stable 1.30.7 and mainline 1.31.9, accessed 20 November 2026
- PHP manual: FastCGI Process Manager configuration — PHP documentation, no date shown, accessed 20 November 2026
- PHP manual: Description of core php.ini directives (cgi.fix_pathinfo) — PHP documentation, no date shown, accessed 20 November 2026
- php-src PHP-8.4: sapi/fpm/fpm/fpm_main.c — PHP project source, branch PHP-8.4, no date shown, accessed 20 November 2026
- php-src PHP-8.0: sapi/fpm/fpm/fpm_main.c — PHP project source, branch PHP-8.0, no date shown, accessed 20 November 2026
- php-src PHP-7.4: sapi/fpm/fpm/fpm_main.c — PHP project source, branch PHP-7.4, no date shown, accessed 20 November 2026
This article was originally published on .