在命令行 ubuntu 16.04 上切换 php 版本 [英] Switch php versions on commandline ubuntu 16.04
问题描述
我已经在我的 Ubuntu 16.04 上安装了 php 5.6 和 php 7.1
I have installed php 5.6 and and php 7.1 on my Ubuntu 16.04
我知道用 Apache 作为我的网络服务器,我可以做到
I know with Apache as my web server, I can do
a2enmod php5.6 #to enable php5
a2enmod php7.1 #to enable php7
当我在 Apache 模块中禁用 php7.1 并启用 php 5.6 时,Apache 会识别更改并按预期使用 php 5.6 解释器.
When I disable php7.1 in Apache modules and enable php 5.6, Apache recognizes the change and uses php 5.6 interpreter as expected.
但是当我从命令行运行内部 php web 服务器时:
But when I run internal php web server from the commandline:
php -S localhost:8888
php 使用 php 7 处理请求.那么如何在命令行中在 php 5.6 和 php 7.1 之间切换?
php handles requests using php 7. So how do I switch between php 5.6 and php 7.1 in the command line ?
推荐答案
交互切换模式
sudo update-alternatives --config php
sudo update-alternatives --config phar
sudo update-alternatives --config phar.phar
手动切换
从 PHP 5.6 =>PHP 7.1
您的系统上设置了默认 PHP 5.6,您需要切换到 PHP 7.1.
Manual Switching
From PHP 5.6 => PHP 7.1
Default PHP 5.6 is set on your system and you need to switch to PHP 7.1.
阿帕奇:
$ sudo a2dismod php5.6
$ sudo a2enmod php7.1
$ sudo service apache2 restart
命令行:
$ 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
从 PHP 7.1 =>PHP 5.6
您的系统上设置了默认 PHP 7.1,您需要切换到 PHP 5.6.
From PHP 7.1 => PHP 5.6
Default PHP 7.1 is set on your system and you need to switch to PHP 5.6.
阿帕奇:
$ sudo a2dismod php7.1
$ sudo a2enmod php5.6
$ sudo service apache2 restart
命令行:
$ sudo update-alternatives --set php /usr/bin/php5.6
这篇关于在命令行 ubuntu 16.04 上切换 php 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!