How To Change PHP Version From Command Line In Ubuntu Example

03-Apr-2023

.

Admin

How To Change PHP Version From Command Line In Ubuntu Example

Hi guys,

Today i will explained How To Change PHP Version From Command Line In Ubuntu. This example is so easy to use in php.

Suppose your system PHP 7.4 and 8.0 both versions installed and you want to switch PHP version 7.4 to 8.0.

So let's start to the example.

If you want to change php version for apache, run the below command:

sudo a2dismod php7.4

sudo a2enmod php8.0

sudo service apache2 restart

If you want to change php version for command line, run the command:

sudo update-alternatives --set php /usr/bin/php8.0

sudo update-alternatives --set phar /usr/bin/phar8.0

sudo update-alternatives --set phar.phar /usr/bin/phar.phar8.0

Now check the PHP version with php --version command. If you want to switch PHP 8.0 to 7.4 version, you can also switch php version for apache and command line.

Apache Version :


sudo a2dismod php8.0

sudo a2enmod php7.4

sudo service apache2 restart

Command Line Verison :

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

sudo update-alternatives --set phar /usr/bin/phar7.4

sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.4

This way you can switch between different php versions in single Ubuntu system.

Now you can check your own.

I hope it can help you...

#PHP 8

#Ubuntu

#PHP