Switching PHP Versions on Ubuntu 16.04 Command Line
Problem:
When running the internal PHP web server on the command line with php -S localhost:8888, PHP requests are handled using PHP version 7, despite enabling PHP 5.6 in Apache modules. How to switch between PHP versions on the command line?
Interactive Switching:
Use the following commands to interactively switch PHP versions:
sudo update-alternatives --config php sudo update-alternatives --config phar sudo update-alternatives --config phar.phar
Manual Switching:
From PHP 5.6 to PHP 7.1:
Apache:
$ sudo a2dismod php5.6 $ sudo a2enmod php7.1 $ sudo service apache2 restart
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
From PHP 7.1 to PHP 5.6:
Apache:
$ sudo a2dismod php7.1 $ sudo a2enmod php5.6 $ sudo service apache2 restart
Command Line:
$ sudo update-alternatives --set php /usr/bin/php5.6
Source:
https://www.digitalocean.com/community/tutorials/how-to-switch-between-multiple-php-versions-on-ubuntu-16-04
The above is the detailed content of How to Switch Between PHP Versions on Ubuntu 16.04 Command Line?. For more information, please follow other related articles on the PHP Chinese website!