How to install different php versions 5.6, 7.0, 7.1, 7.2, 7.3, 7.4 ubuntu

How to install different php versions 5.6, 7.0, 7.1, 7.2, 7.3, 7.4 ubuntu

Hello guys, Sometimes we need to install different php versions on one system, then it can be challenging to run different php versions in one system, So here i will let you know to install different php versions in one ubuntu machine .

Here we will use some ubuntu linux command to instll php with different versions and some required php extensions. Here i will write the command to install for all php version from 5.6. But i will recommend to use latest php version.

We should always use latest stable php version which has latest security patches, speed improvement, latest features etc. And you application would be more secure as compare to other php version.  

Add PPA for PHP

First thing, We will need to add the PPA ondrej/php which provides the PHP packages and other required PHP extensions. So run the following commands into your terminal.

sudo add-apt-repository ppa:ondrej/php

sudo apt-get update
   

After successfully adding ppa we can install any version of php.

Install PHP 7.4

For installing php7.4 we will need to run the command below in our terminal.

sudo apt install php7.4

Now, we can also install many php extension for php version 7.4 using the command below.

sudo apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y

Install PHP 7.3

For Installing php 7.3 version and extension, run the commands below

sudo apt install php7.3

sudo apt install php7.3-common php7.3-mysql php7.3-xml php7.3-xmlrpc php7.3-curl php7.3-gd php7.3-imagick php7.3-cli php7.3-dev php7.3-imap php7.3-mbstring php7.3-opcache php7.3-soap php7.3-zip php7.3-intl -y

Install PHP 7.2

For Installing php 7.2 version and extension, run the commands below

sudo apt install php7.2
sudo apt install php7.2-common php7.2-mysql php7.2-xml php7.2-xmlrpc php7.2-curl php7.2-gd php7.2-imagick php7.2-cli php7.2-dev php7.2-imap php7.2-mbstring php7.2-opcache php7.2-soap php7.2-zip php7.2-intl -y


Install PHP 7.1

For Installing php 7.1 version and extension, run the commands below

sudo apt install php7.1
sudo apt install php7.1-common php7.1-mysql php7.1-xml php7.1-xmlrpc php7.1-curl php7.1-gd php7.1-imagick php7.1-cli php7.1-dev php7.1-imap php7.1-mbstring php7.1-opcache php7.1-soap php7.1-zip php7.1-intl -y


Install PHP 7.0

For Installing php 7.0 version and extension, run the commands below

sudo apt install php7.0
sudo apt install php7.0-common php7.0-mysql php7.0-xml php7.0-xmlrpc php7.0-curl php7.0-gd php7.0-imagick php7.0-cli php7.0-dev php7.0-imap php7.0-mbstring php7.0-opcache php7.0-soap php7.0-zip php7.0-intl -y


Install PHP 5.6

For Installing php 5.6 version and extension, run the commands below

sudo apt install php5.6
sudo apt install php5.6-common php5.6-mysql php5.6-xml php5.6-xmlrpc php5.6-curl php5.6-gd php5.6-imagick php5.6-cli php5.6-dev php5.6-imap php5.6-mbstring php5.6-opcache php5.6-soap php5.6-zip php5.6-intl -y

 If you are working on multiple projects which are built on different php versions then can easily switch from one php version to another php version using the some commands given in the other article as the linke given below.

Switch php versions from php5.6 to php 7.2 or php 7.2 to php5.6