I have Apache (2.2.22 on Debian) configured to handle PHP files via FastCGI:
<FilesMatch ".+.php$">
SetHandler application/x-httpd-php
</FilesMatch>
Action application/x-httpd-php /fcgi-bin/php5-fpm virtual Alias
/fcgi-bin/php5-fpm /fcgi-bin-php5-fpm FastCgiExternalServer
/fcgi-bin-php5-fpm -socket /var/run/php5-fpm.sock -idle-timeout 600 -pass-header Authorization
To show a custom File Not Found (HTTP 404) page is configured in Apache as follows:
<Directory "/home/http/domain/root">
..
ErrorDocument 404 /pagenotfound.htm
..
</Directory>
Requests for non-existing non-PHP files are answered with the custom 404 pagenotfound.htm file. No problem.
But requests for non-existing PHP files are answered with http-status-header "HTTP/1.1 404 Not Found" and contents "File not found.", so not my custom error page. Problem!
The Apache error log shows (in the latter case):
[Sat Nov 21 14:03:07 2015] [error] [client xx.xxx.xx.xx] FastCGI: server "/fcgi-bin-php5-fpm" stderr: Primary script unknown
How can I configure a custom 404 page for non-existing PHP files when using PHP-FPM?
set "ProxyErrorOverride on" in either your global server config or in individual virtual hosts, see http://httpd.apache.org/docs/current/mod/mod_proxy.html#proxyerroroverride
When 'File not found' is shown instead of custom error page for non-existing .php files (and all other non-existing files get the correct custom error page)...
Centos 8, PHP 7.2.11 File: /etc/httpd/conf.d/php.conf
Add 'ProxyErrorOverride On' after the SetHandler
<FilesMatch \.(php|phar)$>
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
ProxyErrorOverride On
</FilesMatch>
Not sure if required, but I then did:
systemctl restart httpd
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With