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:
1 2 3 4 5 6 7 8 |
# Disable the existing PHP version sudo a2dismod php5.6 #replace this with the version you want to disable # Enable the new PHP version sudo a2enmod php7.0 #replace this with the version you want to enable |
Update the PHP version being used in CLI:
1 2 3 4 5 6 7 |
# Replace php7.0 with the version that you want to update sudo update-alternatives --set php /usr/bin/php7.0 # Verify the update php -v |
The output of the last command should dislay the updated PHP version:
1 2 3 4 5 |
PHP 7.0.27-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jan 5 2018 14:12:46) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.27-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans |
You should now be good to go.
Happy coding 🙂
Recent Comments