Bug 66387 - Per directory fcgi handler is ignored if there is a global fcgi handler
Summary: Per directory fcgi handler is ignored if there is a global fcgi handler
Status: NEW
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_proxy_fcgi (show other bugs)
Version: 2.4.54
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-12 14:55 UTC by Bjoern Voigt
Modified: 2022-12-12 19:47 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bjoern Voigt 2022-12-12 14:55:42 UTC
Many users ask if it is possible to have multiple PHP versions in parallel. This is needed if multiple PHP applications in different locations needs special PHP versions.

This works per vhost, but per directory it is tricky to setup.

Testing shows, that the SetHandler directive is ignored, if the is a global or vhost SetHandler for fcgi.

This does not match the documentation of SetHandler:

"SetHandler Directive
Description: Forces all matching files to be processed by a handler
Syntax:	SetHandler handler-name|none|expression
Context: server config, virtual host, directory, .htaccess"

One example:

1) Enable fgci globally using the openSUSE Tumbleweed PHP FPM configuration:
<IfModule mod_proxy_fcgi.c>
	<FilesMatch "\.ph(p[34578]?|tml)$">
		SetHandler "proxy:fcgi://127.0.0.1:9000"
	</FilesMatch>

	<FilesMatch "\.php[34578]?s$">
		SetHandler "proxy:fcgi://127.0.0.1:9000"
	</FilesMatch>

	DirectoryIndex index.php4
	DirectoryIndex index.php5
	DirectoryIndex index.php7
	DirectoryIndex index.php8
	DirectoryIndex index.php
</IfModule>

2) Setup a directory test in webroot with an .htaccess file

# mkdir test
# cat test/.htaccess
SetHandler "proxy:unix:none-existing-path-is-ignored|fcgi://none-existing-localhost-is-ignored"
# cat test/index.php
<?php phpinfo(); ?>

3) Reload Apache

Result: http://localhost/test/index.php shows PHP-Info from PHP 8.1

Now disable the global SetHandler

4) rm /etc/apache2/conf.d/php8-fpm.conf

5) Reload Apache

Result: http://localhost/test/index.php downloads the index.php source code

Now set the correct handler into test/.htaccess

6) cat test/.htaccess

SetHandler "proxy:unix:/var/run/php-fpm-www.sock|fcgi://localhost"

Result: http://localhost/test/index.php shows PHP-Info from PHP 8.1