Programming Tips - Apache: logging AH01071: Got error 'Primary script unknown'

Date: 2025mar27 Language: php Product: Apache 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 only run php when the file exists. In .../conf.d/php.ini 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.