0

I would like to use multiple PHP-FPM versions using FastCGI on same Debian/Apache server. Using:

  • Debian v9.12,
  • Apache v2.4.25,
  • php5.6-fpm,
  • php7.4-fpm,
  • libapache2-mod-fcgid v1:2.3.9-1+b1,
  • libapache2-mod-php5.6 v5.6.40-26+0~20200320.32+debian9~1.gbpec51cd,
  • libapache2-mod-php7.4 v7.4.14-1+0~20210112.34+debian9~1.gbpaa175a.

I would like to use php5.6-fpm, php7.4-fpm on the same server.

The site should use PHP v5.6 by default and should use PHP v7.4 on php74.mysite.com subdomain.

I use the following Apache config files:

mysite.conf:

<IfModule mod_ssl.c>
<VirtualHost *:443>

DocumentRoot "/var/www/mysite.com/htdocs"
ServerName mysite.com:443
ServerAlias *.mysite.com:443 www.mysite.com:443

SecAuditEngine On
RewriteEngine On
SSLEngine on

LogLevel warn
ServerSignature Off


    <FilesMatch "\.php(/.*)$">
        SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/var/www/mysite.com/htdocs"
    </FilesMatch>
 
    <Proxy fcgi://localhost/var/www/mysite.com/htdocs enablereuse=on max=10>
        ProxySet connectiontimeout=3600 timeout=3600
    </Proxy>

    RewriteCond %{REQUEST_FILENAME} \.php$
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
    RewriteRule (.*) - [H=text/html]
 

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

<Directory /var/www/mysite.com/htdocs>
    Options Indexes FollowSymLinks MultiViews
    DirectoryIndex index.php
    AllowOverride None
    Require all granted
</Directory>

ErrorLog /var/www/mysite.com/log/error.log
CustomLog /var/www/mysite.com/log/access.log combined
CustomLog /var/www/mysite.com/log/ssl_request_log \
            "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>                                  
</IfModule>

php74.mysite.conf:

<IfModule mod_ssl.c>

<VirtualHost *:443>

DocumentRoot "/var/www/php74.mysite.com/htdocs"
ServerName php74.mysite.com

SSLEngine on
SecAuditEngine On
RewriteEngine On
SSLProxyEngine on

LogLevel debug
LogLevel alert rewrite:trace8

ProxyPreserveHost On


<Directory /var/www/php74.mysite.com/htdocs>
    Options -Indexes +FollowSymLinks +MultiViews
    AllowOverride All
    Require all granted
</Directory>
    
<FilesMatch "\.php(/.*)$">
        SetHandler  "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost/var/www/php74.mysite.com/htdocs"
</FilesMatch>
<Proxy "fcgi://localhost/var/www/php74.mysite.com/htdocs" enablereuse=on max=10>
</Proxy>


<Directory /var/www/php74.mysite.com/htdocs>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Require all granted
    DirectoryIndex index.php
</Directory>

    
ErrorLog /var/www/php74.mysite.com/log/error.log
CustomLog /var/www/php74.mysite.com/log/access.log combined


CustomLog /var/www/php74.mysite.com/log/ssl_request_log \
            "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>                                  
</IfModule>

Uploaded a phpinfo.php to both site htdocs:

<?php

phpinfo();

?>

Unfortunately on php74.mysite.com displays:

PHP Version 5.6.40-26+0~20200320.32+debian9~1.gbpec51cd
...
Configuration File (php.ini) Path   /etc/php/5.6/fpm
Loaded Configuration File   /etc/php/5.6/fpm/php.ini

How can I force to use PHP v7.4 on php74.mysite.com?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.