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

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

Mary-Kate Olsen
Release: 2024-11-12 11:37:02
Original
208 people have browsed it

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

Switch PHP Versions on Command Line in Ubuntu 16.04

When managing multiple PHP versions on Ubuntu 16.04, it's often necessary to switch between them in the command line. While Apache allows for easy version switching through module management, the internal PHP web server presents a unique challenge.

Interactive Switching Mode

To interactively switch PHP versions, use the following commands:

sudo update-alternatives --config php
sudo update-alternatives --config phar
sudo update-alternatives --config phar.phar
Copy after login

This will present you with a list of available PHP versions and allow you to select the desired one.

Manual Switching

From PHP 5.6 to PHP 7.1

For Apache, run these commands:

$ sudo a2dismod php5.6
$ sudo a2enmod php7.1
$ sudo service apache2 restart
Copy after login

For the command line, execute:

$ 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

For Apache, run these commands:

$ sudo a2dismod php7.1
$ sudo a2enmod php5.6
$ sudo service apache2 restart
Copy after login

For the command line, execute:

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

The above is the detailed content of How to Switch Between PHP Versions 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