Home > Backend Development > PHP Tutorial > How to Switch Between PHP Versions (5.6 and 7.1) on the Command Line in Ubuntu 16.04?

How to Switch Between PHP Versions (5.6 and 7.1) on the Command Line in Ubuntu 16.04?

Linda Hamilton
Release: 2024-11-25 11:44:35
Original
919 people have browsed it

How to Switch Between PHP Versions (5.6 and 7.1) on the Command Line in Ubuntu 16.04?

Switch PHP Versions on Command Line in Ubuntu 16.04

Issue: How can you switch between PHP versions (5.6 and 7.1) in the command line on Ubuntu 16.04 while using the internal PHP web server?

Solution:

There are two main methods to switch PHP versions in the command line:

  1. Interactive Switching Mode:

    Use the following commands to enter the interactive switching mode:

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

    Select the desired PHP version and confirm your choice.

  2. Manual Switching:

    From PHP 5.6 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 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

Credit:
The provided solution is sourced from:

  • [Stack Overflow](https://stackoverflow.com/questions/41877098/switch-php-versions-on-commandline-ubuntu-16-04)

The above is the detailed content of How to Switch Between PHP Versions (5.6 and 7.1) on the Command Line in Ubuntu 16.04?. 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