Date: 2025mar27
Update: 2025sep15
Language: php
Product: Apache Webserver
Keywords: httpd
Q. Apache: Logging AH01071: Got error 'Primary script unknown'
A. This is caused when a robot (usually) attempts to access a .php URL that doesn't exist. So a fix is to only run php when the file exists.
You can set this up in file ../conf.d/php.ini like this:
Change
<IfModule !mod_php.c>
...
<FilesMatch \.(php|phar)$>
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
</FilesMatch>
</IfModule>
to
<IfModule !mod_php.c>
...
<FilesMatch \.(php|phar)$>
# Ensure the .php file exists
<If "-f %{REQUEST_FILENAME}">
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
</If>
</FilesMatch>
</IfModule>
There might be a small speed hit by checking for the existence of each
script before running it.
I expect this will be fixed/changed in the future.
Maybe a option will be added for php-fpm to suppress the error, etc.
That would avoid the possible speed hit.