You must have JavaScript enabled to use the comments.
06-03-2023

Plusieurs versions de php avec Apache2

Il est possible de faire cohabiter plusieurs versions de php sur un serveur Apache2.

Le principe

Dans le répertoire /etc/apache2/sites-available des fichiers permettent de configurer le comportement d'un site

Une fois rédigé, le fichier, qui doit impérativement avoir le suffixe .conf, doit être activé. La lecture du fichier monsite.conf par Apache2 sera requise par la commande:

sudo a2ensite monsite 

Pour configurer un serveur de test en local (sur localhost), on peut simuler le comportement de domaines en les indiquant dans le /etc/hosts:

127.0.0.1 monsite1 monsite2 monsite3

définition

3 lignes dans un virtualhost vont déterminer la version de php à activer

<FilesMatch \.php$>
# For Apache version 2.4.10 and above, use SetHandler to run PHP as a fastCGI process server
  SetHandler "proxy:unix:/run/php/php8.2-fpm.sock|fcgi://localhost"
</FilesMatch>

L'installation des versions de php

Installer le dépot et des versions de php

Nous installerons les version 5.6, 7.0, 7.2, 7.4, 8.0 et 8.2… tant qu'à faire!

sudo add-apt-repository ppa:ondrej/php
sudo apt update
# installer apache2 et le fastCGI
sudo apt install apache2 libapache2-mod-fcgid
# installer les version de php et le FPM
sudo apt-get install php5.6 php5.6-fpm php5.6-mysql libapache2-mod-php5.6 -y
sudo systemctl start php5.6-fpm
sudo apt-get install php7.0 php7.0-fpm php7.0-mysql libapache2-mod-php7.0 -y
sudo systemctl start php7.0-fpm
sudo apt-get install php7.2 php7.2-fpm php7.2-mysql libapache2-mod-php7.2 -y
sudo systemctl start php7.2-fpm
sudo apt-get install php7.4 php7.4-fpm php7.4-mysql libapache2-mod-php7.4 -y
sudo systemctl start php7.4-fpm
sudo apt-get install php8.0 php8.0-fpm php8.0-mysql libapache2-mod-php8.0 -y
sudo systemctl start php8.0-fpm
sudo apt-get install php8.2 php8.2-fpm php8.2-mysql libapache2-mod-php8.2 -y
sudo systemctl start php8.2-fpm
sudo apt install php-fpm
# activer les modules nécessaires
sudo a2enmod actions fcgid alias proxy_fcgi

Vérifier ces services

sudo systemctl status php7.0-fpm

et

sudo systemctl status php7.2-fpm

Activation du module proxyfcgi

sudo a2enmod proxy_fcgi

Un exemple de virtualhost

<VirtualHost *:80>
     ServerAdmin admin@site1.your_domain
     ServerName site1.your_domain
     DocumentRoot /var/www/site1.your_domain
     DirectoryIndex info.php

     <Directory /var/www/site1.your_domain>
	Options Indexes FollowSymLinks MultiViews
	AllowOverride All
	Order allow,deny
	allow from all
     </Directory>

    <FilesMatch \.php$>
      # For Apache version 2.4.10 and above, use SetHandler to run PHP as a fastCGI process server
      SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost"
    </FilesMatch>

     ErrorLog ${APACHE_LOG_DIR}/site1.your_domain_error.log
     CustomLog ${APACHE_LOG_DIR}/site1.your_domain_access.log combined
</VirtualHost>
Tags: informatique