Hello, developers! In this article, we'll see how to install multiple php versions on Ubuntu 22.04. Here, we'll install multiple PHP versions in the Ubuntu 23.04 version. We will use the Ondrej PPA for installing PHP on the Ubuntu 22.04 LTS system. Which contains PHP 8.3, 8.2, 8.1, 8.0, 7.4, 7.3, 7.2. 7.1, 7.0 & PHP 5.6 packages.
In this tutorial, you will learn how to install PHP on Ubuntu 22.04 LTS system. This tutorial is also compatible with Ubuntu 20.04, and 18.04 systems.
Install Multiple PHP Versions Ubuntu
In this step, we'll update the system using the following command.
sudo apt-get update
sudo apt-get upgrade
Next, we'll install the PHP version from ondrej/php library using the following command.
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
Now you can install PHP8.1
on Ubuntu by executing the following command:
sudo apt-get install php8.1 php8.1-fpm
And install some common PHP8.1
extensions.
sudo apt-get install php8.1-mysql php8.1-mbstring php8.1-xml php8.1-gd php8.1-curl
When prompted, press y to confirm the installation.
Now you can install PHP8.0
on Ubuntu by executing the following command:
sudo apt-get install php8.0 php8.0-fpm
And install some common PHP8.0
extensions.
sudo apt-get install php8.0-mysql php8.0-mbstring php8.0-xml php8.0-gd php8.0-curl
Install PHP 7.4
Now you can install PHP7.4
on Ubuntu by executing the following command:
sudo apt-get install php7.4 php7.4-fpm
And install some common PHP7.4
extensions.
sudo apt-get install php7.4-mysql php7.4-mbstring php7.4-xml php7.4-gd php7.4-curl
Now, we'll check the PHP version using the following command.
php -v
Next, we'll switch the PHP version using the following command.
sudo update-alternatives --config php
To change the default version, enter the number that matches the appropriate version you want to make as the default and press ENTER
.
For example, to make PHP 7.4
the default version, type 3
and press ENTER
.
You can execute the command below to change the version straight away:
sudo update-alternatives --set php /usr/bin/php7.4
Now, we'll uninstall PHP using the following command.
sudo apt-get remove php7.4
Also, uninstall all the modules for that version, Run the following command:
sudo apt-get remove php7.4-*
You might also like: