[BlueOnyx:24143] Re: PHP Handler for FPM

Michael Stauber mstauber at blueonyx.it
Thu Jul 30 13:31:12 -05 2020


Hi Jochen,

> there's a customer who wants his file 'xyz' to be interpreted by PHP
> while the file does not have .php as a suffix, how can he do that?
> We tried something like this:
> 
> <FilesMatch "^(xyz)$">
>     ForceType application/x-httpd-php
> </FilesMatch>
> 
> but then the customer has PHP5 which see to be the mod_php option. The site is set to PHP FPM 7.3 which he of course he also wants for his xyz file.

I would recommend not to do that, as there are other and better ways to
achieve this.

The different PHP implementations available on a 5209R or 5210R (DSO,
DSO+mod_ruid2, suPHP and PHP-FPM) all have their different "application"
settings that tell them which files they are responsible for.

For PHP-FPM the Vsite's <VirtualHost> container has something like this:

RewriteRule ^/(.+.php(/.*)?)$
fcgi://127.0.0.1:9004/home/.sites/site1/wwwroot/web/$1 [L,P]

That means only files with the extension of *.php or *.php(.*) are piped
through PHP-FPM. You cannot easily change this in a persistent fashion
without causing issues during further YUM updates.

Even if you could: You shouldn't. Because then every file (or every file
matching the description) would be piped through PHP-FPM. Even images or
regular HTML pages, videos and what not. This adds to the server load
and you'll get thunderous noise in the PHP-FPM logfile about it being
tasked to handle something that clearly isn't a PHP file.

Technically there is also no good reason why a PHP application does not
have the *.php extension. This indicates a fundamental lack of
understanding on behalf of the author of the app and I'd already be wary
of using it.

Now say just the URL needs to be /xyz, then the application can *still*
be named /xyz.php *and* be reachable via the URL /xyz.

How? There are several ways of doing that. But consider using
ProxyPassMatch for example. For this to work find out the group name of
the Vsite. Say it is "site1". Then edit the Apache include file for that
Vsite, which is this:

/etc/httpd/conf/vhosts/site1.include


At the bottom of it append the following line:

ProxyPassMatch "^/xyz(.*)$" "http://www.customer.com/xyz.php"

Save the changes and restart Apache via "systemctl restart httpd".

Now if someone accesses the URL http://www.customer.com/xyz, then Apache
will serve the content of http://www.customer.com/xyz.php instead, but
the URL visible in the browser remains as http://www.customer.com/xyz

This also works via HTTPS, so you don't need a separate rule for that.

-- 
With best regards

Michael Stauber



More information about the Blueonyx mailing list