Apache2 SetHandler for Proxy FCGID is ignored

Asked by AdamR on 2021-02-17

Hello,

It appears that a recent package update, likely for Apache2's "libapache2-mod-fcgid" or related, has caused the "SetHandler" directive to be ignored. This was an important part in being able to direct a VHOST, directory, or individual files to a specific version of PHP when multiple versions of PHP-FPM are installed. (This does not apply to "mod_php".)

On a system with PHP 7.2, 7.3, 7.4, and 8.0 installed (by example) using their respective "php?.?-fpm" packages, and having them all enabled via their respective "a2enconf php?.?-fpm" actions, a VHOST may have this example snippet so it may use PHP 7.2 for compatibility instead of a later version:

```
<IfModule proxy_fcgi_module>
 <FilesMatch ".+\.ph(ar|p|tml)$">
  SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost"
 </FilesMatch>
</IfModule>
```

What happens as of this week is that only the latest version of PHP-FPM is used, most recently 8.0, which can cause serious compatibility problems I'm sure I won't need to go into further here. Currently the only workaround is to switch off all later versions of PHP via "a2disconf" but that defeats the purpose of having a system with multiple versions of PHP available.

I can very confirm that PHP-FPM is being used (albeit the wrong version) using `phpinfo()`, and that switching off the Apache configuration for each version does indicate a version change (to the latest one available) also using `phpinfo()`. This would indicate that the sockets at "/run/php/php?-?.sock" are valid, and that each Apache PHP-FPM configuration points to the right socket.

Looking at the enabled modules all the necessary ones to do this are present: actions alias fcgid proxy proxy_fcgi

It's just SetHandler directives being ignored. I tried moving it out of the "<IfModule proxy_fcgi_module>" condition, which made no change, so the problem is likely with SetHandler itself.

I've also noticed that this issue only seems to be impacting Ubuntu. All of my Debian 10 installations (all 18 of them) still work as expected, which is why I've decided to file this here.

I'm not alone on this. This was asked by someone else at Ask Ubuntu here with a few people verifying the issue: https://askubuntu.com/questions/1316859/php-fpm-working-but-ignoring-version-from-sethandler

Thanks,

Adam

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu libapache2-mod-fcgid Edit question
Assignee:
No assignee Edit question
Solved by:
AdamR
Solved:
2021-02-19
Last query:
2021-02-19
Last reply:
Franco (francogpellegrini) said : #1

I can reproduce this on KDE Neon Stable, and Ubuntu 20.04.2 LTS

Alfredo (alfre) said : #2

Same problem on Ubuntu 16.04.7 LTS

Alfredo (alfre) said : #3

This solved the problem here:

<FilesMatch ".+\.ph(ar|p|tml)$">
    <If "-f %{REQUEST_FILENAME}">
        SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost"
    </If>
</FilesMatch>

Andrew Teg (andrewteg) said : #4

I wrote the original question AdamR linked to at askubuntu.com, and posted the full contents of my /etc/apache2/conf/php5.6-fpm.conf there. I for one already had the solution alfre posted with the REQUEST_FILENAME wrapper, so while I believe that will help some setups, I also believe the issue still remains that AdamR posted here and I posted on askubuntu.com.

If it helps, our server in question is Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-135-generic x86_64) on Rackspace.

Andrew Teg (andrewteg) said : #5

I realized we also had the line @alfre mentioned in the sites-available conf file for the individual site conf file, so I changed it there, and that did the trick for us. I'm still curious why the change and if it was intentional and why it's only affecting Ubuntu and not Debian as @AdamR mentioned.

AdamR (adam-reece) said : #6

Can confirm that wrapping `SetHandler` within a `<If "-f %{REQUEST_FILENAME}">` resolves this. The `<IfModule>` condition is still in place.

```
<IfModule proxy_fcgi_module>
 <FilesMatch ".+\.ph(ar|p|tml)$">
  <If "-f %{REQUEST_FILENAME}">
   SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost"
  </If>
 </FilesMatch>
</IfModule>
```