Home > Article > Backend Development > How to Switch Between PHP Versions on the Command Line in Ubuntu 16.04?
Switch PHP Versions on Command Line in Ubuntu 16.04
When managing multiple PHP versions on Ubuntu 16.04, it's often necessary to switch between them in the command line. While Apache allows for easy version switching through module management, the internal PHP web server presents a unique challenge.
Interactive Switching Mode
To interactively switch PHP versions, use the following commands:
sudo update-alternatives --config php sudo update-alternatives --config phar sudo update-alternatives --config phar.phar
This will present you with a list of available PHP versions and allow you to select the desired one.
Manual Switching
From PHP 5.6 to PHP 7.1
For Apache, run these commands:
$ sudo a2dismod php5.6 $ sudo a2enmod php7.1 $ sudo service apache2 restart
For the command line, execute:
$ 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
From PHP 7.1 to PHP 5.6
For Apache, run these commands:
$ sudo a2dismod php7.1 $ sudo a2enmod php5.6 $ sudo service apache2 restart
For the command line, execute:
$ sudo update-alternatives --set php /usr/bin/php5.6
The above is the detailed content of How to Switch Between PHP Versions on the Command Line in Ubuntu 16.04?. For more information, please follow other related articles on the PHP Chinese website!