Forwarding PHP requests via ProxyPassMatch as a handler when file exists


When you use mod_proxy_fcgi and php-fpm and httpd

You will see in the VirtualHost block in http.conf:

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1

But when you use mod_rewrite will get error 404 like: http://tutorialspots.com/fakepath.php

How to fix this error:

Method 1: install mod_proxy_handler: https://gist.github.com/progandy/6ed4eeea60f6277c3e39

Method 2: for Apache >= 2.4.10:

<FilesMatch .*\.php(/.*)?$>
	SetHandler proxy:fcgi://127.0.0.1:9000
	</FilesMatch>

Full example:

Listen 80

<VirtualHost *:80>

    <Directory /var/www/html/>        
		Options Indexes FollowSymLinks
		AllowOverride All
		Require all granted
    </Directory>

    <Files ".ht*">
        Require all denied
    </Files>

    #ServerAdmin webmaster@example.com
    #ServerName host.example.com

    DocumentRoot "/var/www/html/"

    SetEnvIf Request_URI "^/favicon\.ico$" dontlog
    SetEnvIf Request_URI "^/robots\.txt$" dontlog

    CustomLog "/var/log/httpd/http_access.log" combined env=!dontlog
    ErrorLog "/var/log/httpd/http_error.log"
 
	<FilesMatch .*\.php(/.*)?$>
	SetHandler proxy:fcgi://127.0.0.1:9000
	</FilesMatch>
	
    DirectoryIndex index.php index.html
    
</VirtualHost>

Forwarding PHP requests via ProxyPassMatch as a handler when file exists

Leave a Reply