How to install multiple php versions in ubuntu

How to Install Multiple PHP Versions on Ubuntu

Here we will be installing multiple PHP versions. PHP is a server-side scripting language. PHP language is mostly used for web development. For this, you have to install PHP on your system. PHP language is used for making e-commerce, blogs, and different types of websites.

Here we will use Ondrej PPA for installing PHP to your Ubuntu system. Indrej contains different types of PHP version and their packages we can install and use in our system. We can easily install multiple PHP versions and packages with Ondrej. We are suggested to use the latest PHP version for development.

Step 1: Installing Multiple PHP on Ubuntu

By Ondrej PPA we can install multiple php versions to our system easily. Here we are providing you with some command which you have to follow and run on your Ubuntu system’s terminal. 

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

This repository contains different PHP versions so by this repository we can install different types of PHP versions that we want.

PHP 8.2:

Now you can run the following command to install PHP8.2.

sudo apt-get install php8.2 php8.2-fpm

And install PHP8.2 extensions.

sudo apt-get install php8.2-mysql php8.2-mbstring php8.2-xml php8.2-gd php8.2-curl

After running the command type y to confirm the installation.

PHP 8.1:

Now you can run the following command to install PHP8.1.

sudo apt-get install php8.1 php8.1-fpm

And install PHP8.1 extensions.

sudo apt-get install php8.1-mysql php8.1-mbstring php8.1-xml php8.1-gd php8.1-curl

After running the command type y to confirm the installation.

PHP 8.0:

Now you can run the following command to install PHP8.0.

sudo apt-get install php8.0 php8.0-fpm

And install PHP8.0 extensions.

sudo apt-get install php8.0-mysql php8.0-mbstring php8.0-xml php8.0-gd php8.0-curl

After running the command type y to confirm the installation.

PHP 7.4:

Now you can run the following command to install PHP7.4.

sudo apt-get install php7.4 php7.4-fpm

And install PHP7.4 extensions.

sudo apt-get install php7.4-mysql php7.4-mbstring php7.4-xml php7.4-gd php7.4-curl

After running the command type y to confirm the installation.

PHP 7.3:

Now you can run the following command to install PHP7.3.

sudo apt-get install php7.3 php7.3-fpm

And install PHP7.3 extensions.

sudo apt-get install php7.3-mysql php7.3-mbstring php7.3-xml php7.3-gd php7.3-curl

After running the command type y to confirm the installation.

PHP 7.2:

Now you can run the following command to install PHP7.2.

sudo apt-get install php7.2 php7.2-fpm

And install PHP7.2 extensions.

sudo apt-get install php7.2-mysql php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl

After running the command type y to confirm the installation.

PHP 7.1:

Now you can run the following command to install PHP7.1.

sudo apt-get install php7.1 php7.1-fpm

And install PHP7.1 extensions.

sudo apt-get install php7.1-mysql php7.1-mbstring php7.1-xml php7.1-gd php7.1-curl

After running the command type y to confirm the installation.

Step 2: Check Active PHP Version

After installation by running this command you can verify which is your active PHP version.

Php -v

Step 3: Switch the php version

If you have multiple PHP version installed in ubuntu by this command you can switch between the multiple versions.

sudo update-alternatives --config php

After running this command you can see the multiple PHP versions which installed in your system. You can choose which PHP version you have to use and type the selection number of that.

After this check the PHP version.

Php -v

Step 4: Uninstalling PHP versions.

If you want to remove any php version from your system you can run following command to uninstalling that version.

sudo apt-get remove php8.0

Now you can install as many PHP versions as you can and toggle between them as per your priority and which version you want to use.

Leave a Comment