You can install multiple versions of PHP on your Ubuntu environment. At the time of writing this article, I have the following versions of PHP installed on my development machine as various applications use different versions of PHP:

  • 5.6
  • 7.0
  • 7.1
  • 7.2

Some are still using PHP 5.6, some use PHP 7.0 and so on. I work with various clients who have not upgraded the applications for various reasons and to support them I have to work with different versions of PHP and switch between different versions. I know I can use vagrant to install machines for each type of environtment but not all projects/update are that big to justify setting up a new environment for them. To switch between different versions of PHP on your Ubuntu development machine you can do the following:

Update the PHP version being used with Apache:

 

Update the PHP version being used in CLI:

 

The output of the last command should dislay the updated PHP version:

 

You should now be good to go.

 

Happy coding 🙂