How can I change the PHP version used in console on Ubuntu 20.04? I have all versions in the /etc/php folder, but I don't know where the configuration for the command line version is.
4 Answers
You can do this with update-alternatives. If you would like to do this interactively, you can do this:
sudo update-alternatives --config phpIf you like to specifically choose the PHP version (via an alias or whatnot), you can do this:
sudo update-alternatives --set php /usr/bin/php7.4Of course, be sure to change php7.4 to the actual version you want to switch between.
Please use following command which will ask you to select a number against your required PHP version
sudo update-alternatives --config phpThen select your choice and press enter.
2i just try in Ubuntu20.04 and it works.
// to show the list php installed: sudo update-alternatives --config php
// choose number version that you wanna switchscreenshoot switch php version in ubtuntu
alias setphp="sudo update-alternatives --config php;sudo update-alternatives --config phar; update-alternatives --config phar.phar; a2dismod php*.*;systemctl restart apache2"Put the above alias in ~/.bashrc:
sudo nano ~/.bashrcThen just run this command:
a2enmod php<Your Desired Version> # like, a2enmod php7.4Now you can run the command setphp from your terminal.