Running multiple PHP versions on your server allows you to support legacy applications while keeping up with the latest features and security patches. In this guide, we'll show you how to install PHP versions 5.6, 7.0 through 8.3 with PHP-FPM and FastCGI mode for ISPConfig 3.2 on Ubuntu 20.04 - 24.04. This setup is perfect for web hosting environments, especially on VPS servers.

Step 1: Add the Ondrej PHP Repository

Ubuntu’s default repositories do not provide older versions of PHP, so you'll need to add the Ondrej PHP repository, which offers multiple versions of PHP. Run the following commands to add this repository to your system:

sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

After adding the repository, update the package list:

sudo apt update

Step 2: Install PHP Versions 5.6, 7.0 - 8.3

Now that the Ondrej PHP repository is enabled, you can install the desired PHP versions. Use the following commands to install each PHP version along with the necessary PHP-FPM and FastCGI modules:

Install PHP 5.6

sudo apt install php5.6 php5.6-fpm php5.6-cgi

Install PHP 7.0 - 7.4


sudo apt install php7.0 php7.0-fpm php7.0-cgi
sudo apt install php7.1 php7.1-fpm php7.1-cgi
sudo apt install php7.2 php7.2-fpm php7.2-cgi
sudo apt install php7.3 php7.3-fpm php7.3-cgi
sudo apt install php7.4 php7.4-fpm php7.4-cgi
        

Install PHP 8.0 - 8.3


sudo apt install php8.0 php8.0-fpm php8.0-cgi
sudo apt install php8.1 php8.1-fpm php8.1-cgi
sudo apt install php8.2 php8.2-fpm php8.2-cgi
sudo apt install php8.3 php8.3-fpm php8.3-cgi
        

This will install multiple PHP versions, their FastCGI binaries, and the PHP-FPM services required to manage each version.

Step 3: Configure PHP-FPM Pools for Each Version

Each PHP version installed using PHP-FPM needs its own configuration file (known as a pool). You’ll configure separate pools for each PHP version to handle different websites and applications.

Navigate to the PHP-FPM configuration directory and edit the pool configuration files:

sudo nano /etc/php/5.6/fpm/pool.d/www.conf

Modify the listen directive to specify a unique socket for PHP 5.6:

listen = /run/php/php5.6-fpm.sock

Repeat this process for all other installed PHP versions (7.0 - 8.3) to ensure each version has its own pool file and unique socket. For example, for PHP 7.4, the listen directive would be:

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

Once all pool configurations are set, restart the PHP-FPM services:


sudo systemctl restart php5.6-fpm
sudo systemctl restart php7.0-fpm
sudo systemctl restart php7.1-fpm
sudo systemctl restart php7.2-fpm
sudo systemctl restart php7.3-fpm
sudo systemctl restart php7.4-fpm
sudo systemctl restart php8.0-fpm
sudo systemctl restart php8.1-fpm
sudo systemctl restart php8.2-fpm
sudo systemctl restart php8.3-fpm
        

Step 4: Integrate PHP Versions with ISPConfig 3.2

Now that multiple PHP versions are installed and configured, you can integrate them with ISPConfig 3.2 to allow websites to use different PHP versions. Follow these steps:

  1. Log into your ISPConfig control panel.
  2. Go to System > Server Config and click on the Web tab.
  3. Scroll down to PHP Settings and add the paths to each PHP-FPM binary.

For example, for PHP 7.4, add:

/usr/bin/php7.4-cgi

Repeat this for all PHP versions you want to support, then save the settings. ISPConfig will now allow you to choose different PHP versions for each site hosted on your VPS server.

Step 5: Configure FastCGI for Nginx or Apache

Depending on whether you use Nginx or Apache as your web server, you’ll need to configure FastCGI to handle PHP requests.

Nginx Configuration

For Nginx, open your site's configuration file and ensure the FastCGI block points to the correct PHP-FPM socket. For example, to use PHP 7.4, add the following:


location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
        

Apache Configuration

If you are using Apache, edit the site's virtual host file to specify the PHP version for FastCGI. For example, to use PHP 7.4, add:



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

        

After configuring FastCGI for the appropriate web server, restart Nginx or Apache to apply the changes:

sudo systemctl restart nginx
sudo systemctl restart apache2

Step 6: Testing and Managing PHP Versions

Once the configurations are complete, you can test that each website on your VPS server is running the correct PHP version by creating a phpinfo() file in the website’s root directory:



        

Access the file in your browser, and it will display the PHP version in use. You can now run multiple PHP versions on a single server.

Running Multiple PHP Versions on a VPS

Using a VPS server for hosting multiple PHP versions allows you to efficiently manage legacy applications while also supporting newer PHP versions for modern web applications. With ISPConfig 3.2 and FastCGI mode, you can easily switch between PHP versions per website, providing flexibility for developers and site owners.

Looking for a Reliable VPS Solution?

If you're looking for a scalable and reliable VPS server to host multiple PHP versions and web applications, consider using WindowsVPS. With WindowsVPS, you get high-performance VPS hosting with full control over your server, perfect for hosting multiple PHP environments.

Hai trovato utile questa risposta? 0 Utenti hanno trovato utile questa risposta (0 Voti)