How to switch PHP version in Ubuntu using Terminal

How to switch PHP version in Ubuntu using Terminal

Different projects are working on different php version some of project are working on php 7.4,7.2,7.0 also older version of php projects are working on php version 5.6 and etc.

Before start interchange of php version we assume that you have installed php version 7.4,7.2,7.0 and 5.6,if you have not installed php version you can check my LAMP Installation post or simply search for lamp installtion. 

Please follow below steps to interchange php versoin.

How to switch PHP version in Ubuntu using Terminal

Interchange php version 7.4 To 7.2

Step 1: Open your terminal.

In this first step open your terminal OR simply press Ctrl + Alt + T and add below code to your terminal.

sudo a2dismod php7.4

Then restart apache server and  enable php version whatever you have to enable.Currently we are enable php version 7.2.

sudo service apache2 restart
sudo a2enmod php7.2
sudo service apache2 restart

Interchange php version 7.2 To 7.4

Step 1: Open your terminal.

Open your terminal OR simply press Ctrl + Alt + T and add below code to your terminal.

sudo a2dismod php7.2
sudo service apache2 restart //For restart apache server
sudo a2enmod php7.4
sudo service apache2 restart //For restart apache server

Interchange php version 7.0 To 5.6

Step 1: Open your terminal.

Open your terminal OR simply press Ctrl + Alt + T and add below code to your terminal.

sudo a2dismod php7.0
sudo service apache2 restart //For restart apache server
sudo a2enmod php5.6
sudo service apache2 restart //For restart apache server

Interchange php version 5.6 To 7.0

Step 1: Open your terminal.

Open your terminal OR simply press Ctrl + Alt + T and add below code to your terminal.

sudo a2dismod php5.6
sudo service apache2 restart //For restart apache server
sudo a2enmod php7.0
sudo service apache2 restart //For restart apache server