PHP FPM Working, but ignoring version from SetHandler

Our server is Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-135-generic x86_64).

We followed the directions from https://tecadmin.net/install-multiple-php-version-apache-ubuntu/ a while back and got PHP 5.6 and 7.2 running back when 7.2 was new, and have upgraded and added 7.3 and 7.4 with no problems until this morning. Yesterday it worked fine but today it is not. We package update early yesterday but it didn't require a reboot and don't believe it rebooted overnight on its own as uptime says we're close to 15 days.

So today we set about going through the process again and have done this, restarting apache2 after every step:

Tried: a2enmod actions fcgid alias proxy_fcgi and got: ERROR: Module fcgid does not exist!

Did apt install apache2 libapache2-mod-fcgid and that worked and added the package.

Did a2enmod actions fcgid alias proxy_fcgi and it said everything already enabled.

Checked conf file in /etc/apache2/sites-enabled:

<FilesMatch \.php$>
    SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost"
</FilesMatch>

Tried phpinfo() page and got PHP 7.4.15 instead of expected 5.6.40. We did the same with a 7.3 and got the same 7.4 on phpinfo() using SetHandler of php7.3 as well.

Then tried systemctl status php5.6-fpm and php7.4-fpm and both active (running)

My /etc/apache2/conf/php5.6-fpm.conf file is here for starters, and the one for php7.4-fpm.conf is the same except for mod_php5/7 and the SetHandler version:

# Redirect to local php-fpm if mod_php is not available
<IfModule !mod_php5.c>
<IfModule proxy_fcgi_module>
    # Enable http authorization headers
    <IfModule setenvif_module>
    SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
    </IfModule>

    <FilesMatch ".+\.ph(ar|p|tml)$">
        <If "-f %{REQUEST_FILENAME}">
            SetHandler "proxy:unix:/run/php/php5.6-fpm.sock|fcgi://localhost"
        </If>
    </FilesMatch>
    <FilesMatch ".+\.phps$">
        # Deny access to raw php sources by default
        # To re-enable it's recommended to enable access to the files
        # only in specific virtual host or directory
        Require all denied
    </FilesMatch>
    # Deny access to files without filename (e.g. '.php')
    <FilesMatch "^\.ph(ar|p|ps|tml)$">
        Require all denied
    </FilesMatch>
</IfModule>
</IfModule>

Is there an error here or somewhere else I should look?

FWIW, we have another server with a similar setup and it is having the same issue, but we only need the 5.6 legacy application on that server at this time so we just disabled 7.4 by removing the pointer file in /etc/apache2/conf-enabled/php7.4-fpm.conf and restarting apache2. However, this server needs multiple versions.


Solution 1:

Change:

<FilesMatch \.php$>
    SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost"
</FilesMatch>

for:

<FilesMatch \.php$>
   <If "-f %{REQUEST_FILENAME}">
    SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost"
   </If>
</FilesMatch>

Solution 2:

Since I update my OS (ubuntu 20.04 LTS) on 15 feb 2021, I started to have this PROBLEM. Now php 8.0 is used for all my sites, instead of SetHandler configs