How do I switch between versions of PHP in Apache and the Ubuntu CLI?

How do I switch between versions of PHP in Apache and the Ubuntu CLI?

Answer:

From: https://stackoverflow.com/questions/42619312/switch-php-versions-on-commandline-ubuntu-16-04

Apache:


sudo a2dismod php7.4
sudo a2enmod php8.3
sudo systemctl restart apache2


Command Line:


sudo update-alternatives --set php /usr/bin/php8.3
sudo update-alternatives --set phar /usr/bin/phar8.3
sudo update-alternatives --set phar.phar /usr/bin/phar.phar8.3