John Davidson

Ubuntu 20.10 (Pop OS) with Apache and multiple versions of PHP-FPM FilesMatch directive not working

0 comments
Message:


I have a fresh Pop!OS 20.10 (Basically Ubuntu for those not familiar with Pop!OS). I've installed Apache, php 7.2, 7.4 & 8.0. Each version is running as FPM and each service is up and running. I have several vhosts setup and using FilesMatch to indicate which version of php should run on each host.


The problem is they all show php 8.0 when running phpinfo() no matter what the vhost config says. Anyone have any ideas?


Here's one of the host files:


<VirtualHost zr1.local:80>
<FilesMatch \.php$> # Apache 2.4.10+ can proxy to unix socket
SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost/"
</FilesMatch>
DocumentRoot "/var/www/zr1/web"
ServerName zr1.local
<Directory "/var/www/zr1/web">
AllowOverride All
Options +FollowSymLinks
Order allow,deny
Allow from all
<IfModule mod_rewrite>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
</Directory>


FPM service:


php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2021-02-15 14:38:26 EST; 1h 28min ago
Docs: man:php-fpm7.4(8)
Process: 27667 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/>
Main PID: 27664 (php-fpm7.4)
Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
Tasks: 3 (limit: 38267)
Memory: 11.5M
CGroup: /system.slice/php7.4-fpm.service
├─27664 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
├─27665 php-fpm: pool www
└─27666 php-fpm: pool www

From /etc/php/7.4/fpm/pool.d/www.conf


listen = /run/php/php7.4-fpm.sock

apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2021-02-15 14:54:05 EST; 1h 25min ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 29642 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 29646 (/usr/sbin/apach)
Tasks: 8 (limit: 38267)
Memory: 15.3M
CGroup: /system.slice/apache2.service
├─29646 /usr/sbin/apache2 -k start
├─29647 /usr/sbin/apache2 -k start
├─29648 /usr/sbin/apache2 -k start
├─29649 /usr/sbin/apache2 -k start
├─29650 /usr/sbin/apache2 -k start
├─29651 /usr/sbin/apache2 -k start
├─29652 /usr/sbin/apache2 -k start
└─29705 /usr/sbin/apache2 -k start

Let me know if you need to see anything else.



My Answer:
and 8.0 using PHP-FPM. I want to use different versions of PHP for different directories on my server.

I have set up my Apache virtual hosts to use PHP-FPM for each version of PHP like so:



SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost/"





SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost/"





SetHandler "proxy:unix:/run/php/php8.0-fpm.sock|fcgi://localhost/"



However, when I try to access a PHP file in a directory that should be using a specific version of PHP, it always defaults to the latest version installed (in this case, PHP 8.0).

I have checked that the PHP-FPM pools are running correctly and that the socket files exist in the specified locations. I have also restarted Apache after making changes to the virtual host files.

I'm not sure why the FilesMatch directive is not working as expected. Any help or suggestions would be greatly appreciated.

Rate this post

3 of 5 based on 6177 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us