Grow Your Business Online

Linkysoft Services, Products, Hosting, and Servers

Managing different versions of PHP is crucial for developers who need compatibility across various projects. AlmaLinux 9, combined with Virtualmin/Webmin, makes it easier to install multiple PHP versions. In this guide, we will walk you through the step-by-step process of installing PHP 8.1 and PHP 8.2, managing configurations, and resolving common issues. By the end of this tutorial, you will have both PHP versions running on your AlmaLinux 9 system, ensuring flexibility for your applications.

What Is PHP And Why You Might Need Multiple Versions

PHP is a popular scripting language used for building dynamic websites. Different applications require different PHP versions due to compatibility reasons. Installing both PHP 8.1 and 8.2 on AlmaLinux 9 allows you to run multiple projects requiring different versions of PHP on the same server, all managed by Virtualmin/Webmin.

Prerequisites

  • AlmaLinux 9 server with root or sudo access
  • Virtualmin/Webmin installed on your server
  • Access to the Remi repository for installing PHP versions

Step-by-Step Installation Process

Step 1: Enable the Remi Repository

sudo dnf install epel-release -y

sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y

Step 2: Enable PHP 8.1 and PHP 8.2

Next, enable the modules for both PHP 8.1 and PHP 8.2:

sudo dnf module enable php:remi-8.1 -y

sudo dnf module enable php:remi-8.2 -y

Step 3: Install PHP 8.1 And PHP 8.2

Now install the required PHP versions along with commonly used extensions:

PHP 8.1 Installation:

sudo dnf install php81 php81-php php81-php-cli php81-php-fpm php81-php-mysqlnd php81-php-xml php81-php-mbstring php81-php-gd php81-php-opcache

PHP 8.2 Installation:

sudo dnf install php82 php82-php php82-php-cli php82-php-fpm php82-php-mysqlnd php82-php-xml php82-php-mbstring php82-php-gd php82-php-opcache

Step 4: Configure Apache For PHP Versions

To run both PHP versions on your server, you need to configure Apache to work with PHP-FPM. For each virtual host, assign the correct PHP version:

PHP 8.1 Configuration:

Edit your Apache configuration and add:

SetHandler "proxy:unix:/var/run/php81-php-fpm.sock|fcgi://localhost/"

PHP 8.2 Configuration:

Edit the configuration for PHP 8.2:

SetHandler "proxy:unix:/var/run/php82-php-fpm.sock|fcgi://localhost/"

Step 5: Restart Apache and PHP-FPM Services

After making the configurations, restart Apache and PHP-FPM services:

sudo systemctl restart httpd

sudo systemctl restart php-fpm

Troubleshooting Common Issues

Issue: PHP Version Not Detected

If Apache is not detecting the correct PHP version for a virtual host, ensure that PHP-FPM is running and correctly configured:

sudo systemctl status php81-php-fpm

sudo systemctl status php82-php-fpm

Issue: PHP Modules Not Loading

If certain PHP modules are not loaded, verify their installation:

sudo dnf list installed | grep php

If a module is missing, install it using:

sudo dnf install php81-php-module-name

sudo dnf install php82-php-module-name

Verifying PHP Versions

Create a phpinfo.php file in the root directory of your website to check which version is active:

echo "" > /var/www/html/info.php

Then navigate to http://your-domain.com/info.php to view the active PHP version.

By following the steps outlined above, you should now have both PHP 8.1 and PHP 8.2 installed and running on AlmaLinux 9, allowing you to host multiple websites with different PHP requirements on the same server.

Was this answer helpful? 0 Users Found This Useful (0 Votes)

Search the Knowledge Base

Share