How to Change PHP Version in Ubuntu Server?

By Hardik Savani May 14, 2024 Category : Ubuntu Server

Hi,

This article goes in detailed on how to change php version in ubuntu. you can see how to change php version command line. if you have question about how to change php version in ubuntu 20.04 then i will give simple example with solution. I’m going to show you about change php version linux.

If you installed multiple php version in your ubuntu system or server and you need to change default php version then i will help you with different ways to change php version in ubuntu 21.10, ubuntu 21.04, ubuntu 20.04, ubuntu 18.04 and ubuntu 16.04.

let's see commands one by one.

Way 1: Change PHP Version

you can change php version by following command:

sudo update-alternatives --config php

you have to choose from list as bellow:

now let's restart server:

sudo service apache2 restart

Way 2: Change PHP Version

Here, you need to a2dismod old version and a2enmod new php version so let's run following command:

sudo a2dismod php7.3

sudo a2enmod php7.4

now let's restart server:

sudo service apache2 restart

Way 3: Change PHP Version

You can direct change php version by following command:

sudo update-alternatives --set php /usr/bin/php7.4

now let's restart server:

sudo service apache2 restart

i hope it can help you...

Tags :
Shares