Home > Article > Backend Development > How do I Switch Between PHP Versions in Ubuntu 16.04 Command Line?
Users may encounter situations where they need to switch between multiple PHP versions when working on a Ubuntu 16.04 system. While it's straightforward to manage PHP versions when using Apache as the web server, the process for switching versions in the command line differs. Let's explore the methods for switching between PHP versions in the command line environment.
To switch PHP versions interactively, execute the following commands in a terminal:
sudo update-alternatives --config php sudo update-alternatives --config phar sudo update-alternatives --config phar.phar
This will present a list of available PHP versions and allow you to choose the desired version.
Alternatively, manual switching can be achieved by updating the alternatives configuration.
If PHP 5.6 is currently active and you want to switch to PHP 7.1, execute the following commands:
For Apache:
sudo a2dismod php5.6 sudo a2enmod php7.1 sudo service apache2 restart
For Command Line:
sudo update-alternatives --set php /usr/bin/php7.1 sudo update-alternatives --set phar /usr/bin/phar7.1 sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.1
To switch from PHP 7.1 to PHP 5.6, execute these commands:
For Apache:
sudo a2dismod php7.1 sudo a2enmod php5.6 sudo service apache2 restart
For Command Line:
sudo update-alternatives --set php /usr/bin/php5.6
By following these steps, you can effectively switch between PHP versions in the command line environment on Ubuntu 16.04, allowing for flexibility in development and troubleshooting.
The above is the detailed content of How do I Switch Between PHP Versions in Ubuntu 16.04 Command Line?. For more information, please follow other related articles on the PHP Chinese website!