Fix Apache AH01071: Got error 'Primary script unknown' (php-fpm)
Apache AH01071 'Primary script unknown': php-fpm found no file at the path Apache sent. Tell a missing .php request from an Apache/FPM path mismatch.
[Mon Oct 26 21:37:40.226036 2026] [proxy_fcgi:error] [pid 10:tid 18] [client 203.0.113.10:59230] AH01071: Got error 'Primary script unknown'Apache (mod_proxy_fcgi) told php-fpm to run a script at some path, and php-fpm found no file there. The browser gets File not found. with a 404. There are two causes: **a request for a .php that does not exist** (bots probing wp-login.php and the like), or Apache and php-fpm seeing the same file under different paths.
[1] Check whether real pages 404 as well. That splits the causes.
$ curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1/index.php$ curl -s http://127.0.0.1/index.php| Result | Cause | Go to |
|---|---|---|
an existing index.php also returns 404, File not found. | path mismatch | [2], [3] |
existing files 200, only unknown names 404 | requests for missing files (usually bots) | [4] |
403, Access denied. | file permissions | [5] |
[2] With SetHandler, Apache's own path is what gets sent. The official mod_proxy_fcgi docs say this form lets the normal URI-to-filename mapping happen in the server and passes the local filesystem result to the backend. So php-fpm must see the file at the same path.
DocumentRoot "/usr/local/apache2/htdocs"<FilesMatch "\.php$"> SetHandler "proxy:fcgi://127.0.0.1:9000"</FilesMatch>Here php-fpm only had the files under /var/www/html, so even the existing index.php returned 404. This is typical when Apache and php-fpm run in separate containers, on separate hosts, or in a chroot. Make both sides use the same path. In this example, changing Apache's DocumentRoot and <Directory> to /var/www/html and mounting the same files there gave 200 and php ok 8.3.36.
[3] With ProxyPassMatch, check the path after fcgi://. This form appends the request URI to that path, so the prefix must be where the files live on the php-fpm side.
ProxyPassMatch "^/(.*\.php(/.*)?)$" "fcgi://127.0.0.1:9000/var/www/html/$1"A wrong prefix of /srv/www/ produced the same AH01071 and 404 as [2]; changing it to php-fpm's real /var/www/html/ returned 200.
[4] If the paths match and only unknown names fail, stop sending missing files to php-fpm. The conf-available/php8.3-fpm.conf shipped by Ubuntu's php8.3-fpm package matches on the extension only:
<FilesMatch ".+\.ph(?:ar|p|tml)$"> SetHandler "proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost" </FilesMatch>So a request for nope.php, which is not on disk, still reaches php-fpm and leaves an AH01071 line. It is harmless but fills the log. Wrap SetHandler in <If "-f %{REQUEST_FILENAME}"> to pass only existing files:
<FilesMatch ".+\.ph(?:ar|p|tml)$"> <If "-f %{REQUEST_FILENAME}"> SetHandler "proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost" </If> </FilesMatch>On 2.4.69, with this change Apache answered nope.php with its own 404, and nothing showed up in the php-fpm access log or the Apache error log. Copy the file before editing (sudo cp -a /etc/apache2/conf-available/php8.3-fpm.conf /root/) and apply with sudo apache2ctl configtest && sudo systemctl reload apache2. To undo, put the copy back with sudo cp -a /root/php8.3-fpm.conf /etc/apache2/conf-available/ and run the same command. If your app router uses paths like index.php/route, open such a URL after the change; that case was not tested.
[5] 403 with Access denied. is a different message. php-fpm found the file but its user (www-data in both environments) could not read it.
[Mon Oct 26 21:38:00.912049 2026] [proxy_fcgi:error] [pid 9:tid 23] [client 203.0.113.10:35566] AH01071: Got error 'Unable to open primary script: /var/www/html/index.php (Permission denied)'That is index.php set to 600 (readable by root only). Check the file and its parent directories with ls -l, and make them readable for www-data (for example 644 for files, 755 for directories).
SetHandler with proxy:fcgi needs the proxy_fcgi module; fix a missing module the same way as in Invalid command 'RewriteEngine'. If a 403 comes from access rules rather than file permissions, see AH01630.
Analyze your Apache log in the browser ↗ — nothing is uploaded.