Switch php versions on commandline ubuntu 16.04

2019-01-29 21:06发布

I have installed php 5.6 and and php7.1 on my ubuntu 16.04

I know with apache as my web server, i can do

a2enmod php5.6 to enable php5
a2enmod php7.1 to enable php7

When i disable php7.1 in apache modules and enable php5.6, apache recognizes the change and uses php5.6 interpreter as expected.

But when i run internal php web server from the commandline :-

php -S localhost:8888

php handles requests using php7 , how do i switch between php6.6 and php7.1 in the commandline ?

12条回答
贪生不怕死
2楼-- · 2019-01-29 21:18

From PHP 5.6 => PHP 7.1

$ sudo a2dismod php5.6
$ sudo a2enmod php7.1

for old linux versions

 $ sudo service apache2 restart

for more recent version

$ systemctl restart apache2
查看更多
等我变得足够好
3楼-- · 2019-01-29 21:21

To list all available versions and choose from them :

sudo update-alternatives --config php

Or do manually

sudo a2dismod php7.1 // disable
sudo a2enmod php5.6  // enable
查看更多
相关推荐>>
4楼-- · 2019-01-29 21:22

You can use the below script to switch between PHP version easily I have included phpize configuration too.

https://github.com/anilkumararumulla/switch-php-version

Download the script file and run

sh switch.sh
查看更多
啃猪蹄的小仙女
5楼-- · 2019-01-29 21:23

Interactive switching mode

sudo update-alternatives --config php

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.

Apache:

$ sudo a2dismod php5.6
$ sudo a2enmod php7.1
$ sudo service apache2 restart

Command Line:

$ sudo update-alternatives --set php /usr/bin/php7.1

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.

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

查看更多
Rolldiameter
6楼-- · 2019-01-29 21:23

Type given command in your terminal..

For disable the selected PHP version...

    • sudo a2dismod php5
    • sudo service apache2 restart
  1. For enable other PHP version....

    • sudo a2enmod php5.6
    • sudo service apache2 restart

It will upgrade Php version, same thing reverse if you want version downgrade, you can see it by PHP_INFO();

查看更多
【Aperson】
7楼-- · 2019-01-29 21:28

I think you should try this

From php5.6 to php7.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

From php7.1 to php5.6

sudo a2dismod php7.1
sudo a2enmod php5.6
sudo service apache2 restart

sudo update-alternatives --set php /usr/bin/php5.6
sudo update-alternatives --set phar /usr/bin/phar5.6
sudo update-alternatives --set phar.phar /usr/bin/phar.phar5.6
查看更多
登录 后发表回答