Switch php version on command line ubuntu 16.04
P粉029327711
P粉029327711 2023-10-10 22:42:14
0
1
569

I have installed php 5.6 and php 7.1 on Ubuntu 16.04

I know I can do it using Apache as my web server

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

When I disable php7.1 and enable php 5.6 in the Apache module, Apache recognizes the change and uses the php 5.6 interpreter as expected.

But when I run the internal php web server from the command line:

php -S localhost:8888

php uses php 7 to handle requests. So how do I switch between php 5.6 and php 7.1 from the command line?

P粉029327711
P粉029327711

reply all (1)
P粉504080992

Interactive switching mode

sudo update-alternatives --config php sudo update-alternatives --config phar sudo update-alternatives --config phar.phar

Manual switching

From PHP 5.6 => PHP 7.1

Your system settings default to PHP 5.6, 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 $ sudo update-alternatives --set phar /usr/bin/phar7.1 $ sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.1

From PHP 7.1 => PHP 5.6

Your system is set to default PHP 7.1, 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

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!