If multiple PHP versions are installed on Ubuntu, you can choose which version is used by default from the command line.
Run:
Ubuntu will display the installed PHP versions, for example:
Enter the number for the PHP version you want to use.
Then confirm the active version:
Important
update-alternatives changes the PHP version used by the terminal/CLI.
It does not necessarily change the PHP version used by a website.
If the server uses PHP-FPM with Nginx, the site's Nginx configuration may still point to a specific PHP-FPM socket, such as:
To see the installed PHP-FPM versions:
After changing a website to another PHP-FPM version, restart the required services, for example:
Use php -v for the CLI version and check the web server/PHP-FPM configuration separately when changing the PHP version used by a Laravel website.