This tutorial will show you how to install multiple PHP versions on a single Ubuntu 20.04 LTS or similar Linux system.
First, we will need to add the requisite Personal Package Archive (PPA). PPAs are software repositories designed for Ubuntu users and are easier to install than other third-party repositories. PPAs are often used to distribute pre-release software so that it can be tested or the latest packages are not available in the default repositories.
A PPA is maintained for PHP installation on Ubuntu systems so we will use the commands below to add the PPA to your system.
$ sudo apt update $ sudo apt install software-properties-common $ sudo add-apt-repository ppa:ondrej/php
For this tutorial, we will be adding PHP 8.0 and PHP 7.4 using the following commands:
$ sudo apt update -y $ sudo apt install php8.0 php8.0-fpm -y $ sudo apt install php7.4 php7.4-fpm -y
After installation, PHP-fpm services will be started automatically. Use the following commands to make sure both services are running.
$ sudo systemctl status php8.0-fpm $ sudo systemctl status php7.4-fpm
Congratulations! You now have two versions of PHP on your Ubuntu system. That’s not all, you may want to follow this tutorial to see how to install PHP modules for each of these versions.
If you are configuring Apache with PHP then all you would need to do is point to the right php.ini file for the appropriate version as shown in this post.
For the above installations, these would usually be the locations of the php.ini files:
##PHP 8.0 /etc/php/8.0/fpm/php.ini ##PHP 7.4 /etc/php/7.4/fpm/php.ini