Are you are learning about “How to Switch PHP versions on Commandline ubuntu“? In today’s article, I will provide solutions for you to solve the issues. Please follow the below steps to get the problem resolved now
Table of Contents
How to switch PHP versions using Commandline Ubuntu
To switch PHP versions on Commandpne Ubuntu, list all versions and then use the sudo update-alternatives-phpphp command. Next, do manual sudo a2dismod PHP7.1 to disable it and then use this command to enable sudo-a2enmod PHP5.6
Method 1: Manual switching
This command line is used when you need to use PHP 7.1
sudo a2dismod php5.6
sudo a2enmod php7.1
sudo service apache2 restart
You can also
sudo update-alternatives --set php /usr/bin/php7.1
sudo update-alternatives --set phar /usr/bin/phar7.1
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.1
Method 2: Change from PHP 7.1 to PHP 5.6
This command line is used when you need to use PHP 5.6
sudo a2dismod php7.1
sudo a2enmod php5.6
sudo service apache2 restart
sudo update-alternatives --set php /usr/bin/php5.6
Method 3: Interactive switching mode
sudo update-alternatives --config php
sudo update-alternatives --config phar
sudo update-alternatives --config phar.phar
Method 4: Enable and Disable
You can list all versions available and then choose one.
sudo update-alternatives --config php
Then, do it manually.
sudo a2dismod php7.1 //disable
sudo a2enmod php5.6 //enable
Final Words
The above are useful solutions for the question “How to Switch PHP versions on Commandline ubuntu?”, if you can’t solve it well. Please leave a message.