xxxxxxxxxx
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 the
sudo nano ~/.bashrc
#After the above command just run this command
a2enmod php<Your Desired Version> # like, a2enmod php7.4
Now you can run command "setphp" from your terminal.
xxxxxxxxxx
update-alternatives --set php /usr/bin/php7.4
update-alternatives --set phar /usr/bin/phar7.4
update-alternatives --set phar.phar /usr/bin/phar.phar7.4
update-alternatives --set phpize /usr/bin/phpize7.4
update-alternatives --set php-config /usr/bin/php-config7.4