You can switch between different versions of PHP on Ubuntu by using a tool called "php version manager" (php-switch). Here are the steps to switch PHP versions using this tool:
Install php-switch:
List available PHP versions:
Choose the desired PHP version:
Check the active PHP version:
Note: You can also switch between PHP versions manually by creating symbolic links in the **/etc/alternatives/**
directory. However, this method is more complicated and less recommended.
If you have multiple websites running on your Ubuntu machine and each of them needs a different PHP version, you can either switch between versions for each site using virtual hosts or use tools like php-fpm to run each site on its own PHP version.
Here are some examples of using the **php-switch**
tool to switch between different versions of PHP on Ubuntu:
To switch to PHP 7.4:
To switch to PHP 7.3:
To switch to PHP 5.6:
Note: The available PHP versions that you can switch to depend on what is installed on your system. The examples above assume that the desired versions are already installed