L'expertise web et mobile au service des TPE/PME

Exécuter plusieurs Versions de PHP sur un serveur Apache, PHP-FPM et Ubuntu 20.04

Vous pouvez utiliser ensemble Apache et PHP-FPM pour héberger plusieurs applications Web PHP, chacune utilisant une version différente de PHP, toutes sur le même serveur, et toutes en même temps.

Étape 1 - Installation des Versions PHP 7.0 et 7.2 avec PHP-FPM

sudo apt-get install php7.2 php7.2-fpm php7.3 php7.3-fpm  libapache2-mod-fcgid -y
sudo systemctl start php7.2-fpm
sudo systemctl start php7.3-fpm
sudo a2enmod actions fcgid alias proxy_fcgi
sudo systemctl restart apache2

Étape 2 — Création de structures répertoire pour les deux sites Web

Par défaut, le serveur Apache fonctionne comme un utilisateur www-data et un groupe www-data. Pour vous assurer que vous avez la propriété et les permissions correctes des répertoires root de votre site web, exécuter les commandes suivantes :

sudo chown -R www-data:www-data /var/www/site1.your_domain
sudo chown -R www-data:www-data /var/www/site2.your_domain
sudo chmod -R 755 /var/www/site1.your_domain
sudo chmod -R 755 /var/www/site2.your_domain

Étape 3 — Configuration d'Apache pour les deux sites Web

      ServerAdmin admin@site1.your_domain
      ServerName site1.your_domain
      DocumentRoot /var/www/site1.your_domain
      DirectoryIndex info.php
     
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
     
            # 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"

      ErrorLog ${APACHE_LOG_DIR}/site1.your_domain_error.log
      CustomLog ${APACHE_LOG_DIR}/site1.your_domain_access.log combined

Enregistrer et fermer le fichier lorsque vous avez terminé. Vérifier ensuite le fichier de configuration Apache pour toutes erreurs de syntaxe :

sudo apachectl configtest

Enfin, redémarrer le service Apache pour implémenter vos changements :

sudo systemctl restart apache2