Home  >  Article  >  Backend Development  >  How do I Switch Between PHP Versions in Ubuntu 16.04 Command Line?

How do I Switch Between PHP Versions in Ubuntu 16.04 Command Line?

Linda Hamilton
Linda HamiltonOriginal
2024-11-11 21:41:03617browse

How do I Switch Between PHP Versions in Ubuntu 16.04 Command Line?

Determining the Active PHP Version in Ubuntu 16.04

Users may encounter situations where they need to switch between multiple PHP versions when working on a Ubuntu 16.04 system. While it's straightforward to manage PHP versions when using Apache as the web server, the process for switching versions in the command line differs. Let's explore the methods for switching between PHP versions in the command line environment.

Interactive Switching Mode

To switch PHP versions interactively, execute the following commands in a terminal:

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

This will present a list of available PHP versions and allow you to choose the desired version.

Manual Switching

Alternatively, manual switching can be achieved by updating the alternatives configuration.

From PHP 5.6 to PHP 7.1

If PHP 5.6 is currently active and you want to switch to PHP 7.1, execute the following commands:

For Apache:

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

For 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

To switch from PHP 7.1 to PHP 5.6, execute these commands:

For Apache:

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

For Command Line:

sudo update-alternatives --set php /usr/bin/php5.6

By following these steps, you can effectively switch between PHP versions in the command line environment on Ubuntu 16.04, allowing for flexibility in development and troubleshooting.

The above is the detailed content of How do I Switch Between PHP Versions in Ubuntu 16.04 Command Line?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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