Oftentimes, you may have multiple PHP versions installed on your Ubuntu server, You can easily determine what version should be the default one. These actions may require one to have super user privileges i.e sudo. Ensure the user

If you want PHP 8.1 to be the default, run:

update-alternatives --set php /usr/bin/php8.1

Aleternatively you can use the following command

sudo update-alternatives --config php

That command will list for you available PHP versions from which you can then choose the one you intend to use.

Similarly, to set PHP 8.0 as the default, run:

update-alternatives --set php /usr/bin/php8.0

And finally, if you want to use PHP 7.4, run:

update-alternatives --set php /usr/bin/php7.4

You can verify what version of PHP you’re using with the following command:

php -v

If you’re using Apache, you can configure Apache to use PHP 8.0 with the following command:

sudo a2enmod php8.1

And then restart Apache for the changes to take effect:

sudo systemctl restart apache2

 

Note that having two PHP versions enabled simultaneously may cause Apache to stop working. Ensure to enable only one of the installed PHP versions. To disable an installed PHP version, run:

sudo a2dismod php8.0

The above command will disable PHP version 8.0, while the following command will disable PHP version 8.0

sudo a2dismod php8.1

I hope that you get the gist.