Home > Backend Development > PHP Tutorial > How to Switch Between PHP Versions on Ubuntu 16.04 Command Line?

How to Switch Between PHP Versions on Ubuntu 16.04 Command Line?

Linda Hamilton
Release: 2024-11-11 16:20:03
Original
277 people have browsed it

How to Switch Between PHP Versions on Ubuntu 16.04 Command Line?

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
Copy after login

Manual Switching:

From PHP 5.6 to PHP 7.1:

  • Apache:

    $ sudo a2dismod php5.6
    $ sudo a2enmod php7.1
    $ sudo service apache2 restart
    Copy after login
  • 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
    Copy after login

    From PHP 7.1 to PHP 5.6:

  • Apache:

    $ sudo a2dismod php7.1
    $ sudo a2enmod php5.6
    $ sudo service apache2 restart
    Copy after login
  • Command Line:

    $ sudo update-alternatives --set php /usr/bin/php5.6
    Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template