Home  >  Q&A  >  body text

Switch php version on command line ubuntu 16.04

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粉029327711P粉029327711348 days ago618

reply all(1)I'll reply

  • P粉504080992

    P粉5040809922023-10-11 14:07:31

    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

    reply
    0
  • Cancelreply