Oftentimes, you may have multiple PHP versions installed on your Ubuntu server, You can easily determine what version should be the default one.

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

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

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 can 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.