How To Switch One PHP Version To Another In Linux

Sometimes we need to change the PHP version in our Linux machine. In this tutorial, we will see that how to switch PHP versions in Ubuntu, Debian, red hut, or any Linux-based distros. Let assume we have installed PHP 7.3, PHP 7.4 and PHP 8  version in our Linux server. Now we need to switch the PHP version from PHP 8 to PHP 7.4 let assume.

So what do we have to do to change the PHP version in Linux? Just follow this below command one after another:

sudo a2dismod php7.3 php7.4 php8.0
sudo a2enmod php8.0
sudo service apache2 restart

sudo update-alternatives --set php /usr/bin/php8.0
sudo update-alternatives --set phar /usr/bin/php8.0
sudo update-alternatives --set phar.phar /usr/bin/phar.phar8.0
sudo update-alternatives --set phpize /usr/bin/phpize8.0
sudo update-alternatives --set php-config /usr/bin/php-config8.0

 

Now if you run below command then you will see the below output:

php -v

 

Then the output will be PHP 8 cause we are enabled PHP 8 version in our Linux server.

 

output
PHP 8.0.14 (cli) (built: Dec 20 2021 21:32:16) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.14, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.14, Copyright (c), by Zend Technologies

 

Read also: How to Install PHP 8 on Debian 10 Buster

 

Hope now you know how to switch PHP from one version to another version in Linux.

 

#linux