Our server is Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-135-generic x86_64).
We followed the directions from 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.
55 Answers
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> 5 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
I'm experiencing the exact same on my Ubuntu WSL setup. However the following article was helpfull for a co-worker of mine so it might help you out aswell.
Avoid using ProxyPassMatch
# don't
<IfModule mod_proxy.c> ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/
</IfModule>Since ProxyPassMatch takes precedence over FilesMatch which u use for SetHandler
source:
2Run updates. I had the same problem, now realized it started after the last set of php updates. Just ran the latest updates again and now it works again.
Okay, spoke to soon, the updates didn't fix it.
Here's what did work for me:
EDIT: This was put in the /etc/apache2/sites-available/site1.local.conf. Here's the entire file:
<VirtualHost site1.local:80> <IfModule !mod_php7.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/php7.2-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> DocumentRoot "/var/www/site1/docroot" ServerName site1.local <Directory "/var/www/site1/docroot"> AllowOverride All Options +FollowSymLinks Order allow,deny Allow from all <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /app.php [QSA,L] </IfModule> </Directory>
</VirtualHost>Essentially this is the code copied from the /etc/conf-available/php7.2-fpm.conf file. As I'm not an expert on Apache I can't explain why it worked when the simpler statement didn't. But I've edited three different vhosts and they are now getting the correct version of PHP.
5I'm using Ubuntu 20.04, I've experienced exactly same problem - only one version of PHP was showing up, the latest one. I tried to setup three PHP versions to run with the same Apache simultaneously.
It looked to me as if SetHandler line for all three configs was set to the same value of last loaded config file. Config files was listed in following order in directory:
- /etc/apache2/conf-enabled/php5.6-fpm.conf
- /etc/apache2/conf-enabled/php7.4-fpm.conf
- /etc/apache2/conf-enabled/php8.1-fpm.conf
Apache logs showed, every virtualhost I've created, which was supposed to run different version of PHP, was trying to connect to the same unix socket of php8.1.
Alfredos answer didn't solve the problem on its own for me.
Solution which worked for me was switching from using unix sockets to TCP sockets, as form of communication between apache2 and php-pfm. To do that, I've modified those three files to set ip and listening port of php-pfm.
in file:/etc/php/5.6/fpm/pool.d/
listen = 127.0.0.1:9056in file:/etc/php/7.4/fpm/pool.d/
listen = 127.0.0.1:9074in file:/etc/php/8.1/fpm/pool.d/
listen = 127.0.0.1:9081To reflect above changes in Apache, I've modified files: /etc/apache2/conf-enabled/php*-fpm.conf and /etc/apache2/sites-enabled/php*.mydomain.conf so Apache can connect to proper ip/port. Config files incorporates Alfredos answer.
file /etc/apache2/conf-enabled/php5.6-fpm.conf looks like this:
<IfModule !mod_php5.c>
<IfModule proxy_fcgi_module> <IfModule setenvif_module> SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1 </IfModule> <FilesMatch ".+\.ph(ar|p|tml)$"> <If "-f %{REQUEST_FILENAME}"> SetHandler "proxy:fcgi://localhost:9056" </If> </FilesMatch> <FilesMatch ".+\.phps$"> Require all denied </FilesMatch> <FilesMatch "^\.ph(p[3457]?|t|tml|ps)$"> Require all denied </FilesMatch>
</IfModule>
</IfModule>file /etc/apache2/conf-enabled/php7.4-fpm.conf looks like this:
<IfModule !mod_php7.c>
<IfModule proxy_fcgi_module> <IfModule setenvif_module> SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1 </IfModule> <FilesMatch ".+\.ph(ar|p|tml)$"> <If "-f %{REQUEST_FILENAME}"> SetHandler "proxy:fcgi://localhost:9074" </If> </FilesMatch> <FilesMatch ".+\.phps$"> Require all denied </FilesMatch> <FilesMatch "^\.ph(ar|p|ps|tml)$"> Require all denied </FilesMatch>
</IfModule>
</IfModule>file /etc/apache2/conf-enabled/php8.1-fpm.conf looks like this:
<IfModule !mod_php8.c>
<IfModule proxy_fcgi_module> <IfModule setenvif_module> SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1 </IfModule> <FilesMatch ".+\.ph(ar|p|tml)$"> <If "-f %{REQUEST_FILENAME}"> SetHandler "proxy:fcgi://127.0.0.1:9081" </If> </FilesMatch> <FilesMatch ".+\.phps$"> Require all denied </FilesMatch> <FilesMatch "^\.ph(ar|p|ps|tml)$"> Require all denied </FilesMatch>
</IfModule>
</IfModule>My virtual hosts files looks like this:
/etc/apache2/sites-enabled/php56.mydomain.com.conf :
<VirtualHost *:80> ServerName php56.mydomain.com ServerAlias DocumentRoot /var/www/php56 <Directory /var/www/php56> Options -Indexes +FollowSymLinks +MultiViews AllowOverride All Require all granted </Directory> <FilesMatch \.php$> <If "-f %{REQUEST_FILENAME}"> SetHandler "proxy:fcgi://127.0.0.1:9056" </If> </FilesMatch> LogLevel debug ErrorLog ${APACHE_LOG_DIR}/php56.error.log CustomLog ${APACHE_LOG_DIR}/php56.access.log combined
</VirtualHost>/etc/apache2/sites-enabled/php74.mydomain.com.conf :
<VirtualHost *:80> ServerName php74.mydomain.com ServerAlias DocumentRoot /var/www/php74 <Directory /var/www/php74> Options -Indexes +FollowSymLinks +MultiViews AllowOverride All Require all granted </Directory> <FilesMatch \.php$> <If "-f %{REQUEST_FILENAME}"> SetHandler "proxy:fcgi://127.0.0.1:9074" </If> </FilesMatch> LogLevel debug ErrorLog ${APACHE_LOG_DIR}/php74.error.log CustomLog ${APACHE_LOG_DIR}/php74.access.log combined
</VirtualHost>/etc/apache2/sites-enabled/php81.mydomain.com.conf :
<VirtualHost *:80> ServerName php81.mydomain.com ServerAlias DocumentRoot /var/www/php81 <Directory /var/www/php81> Options -Indexes +FollowSymLinks +MultiViews AllowOverride All Require all granted </Directory> <FilesMatch \.php$> <If "-f %{REQUEST_FILENAME}"> SetHandler "proxy:fcgi://127.0.0.1:9081" </If> </FilesMatch> LogLevel debug ErrorLog ${APACHE_LOG_DIR}/php81.error.log CustomLog ${APACHE_LOG_DIR}/php81.access.log combined
</VirtualHost>For reference:
#apache2 -v
Server version: Apache/2.4.41 (Ubuntu)
Server built: 2021-10-14T16:24:43I hope it helps and spare You some time.
EDIT:To answer your question, is there an error in your config. Line with SetHandler may be a problem if you use TCP sockets, because port is not specified and that could cause Apache trying to connect to same PHP version.
Where else to look for: Check if you have proper SetHandler lines in those files as well: /etc/apache2/sites-enabled/php*.mydomain.conf
Check if SetHandler lines from above files match "listen" lines from following files:/etc/php/*/fpm/pool.d/
1