Home > Article > Backend Development > How to install different PHP (5.6, 7.0 and 7.1) versions in Ubuntu?
In this article, we will introduce to you how to use PPA (full name Personal Package Archives, personal package documents) to install different PHP versions (5.6, 7.0 and 7.1) in Ubuntu and set up PHP used on the Ubuntu system Default version.
Note: PHP 7.x is a stable version supported in the Ubuntu software repositories, you can confirm this by running the apt command below.
$sudo apt show php OR $ sudo apt show php -a
Show PHP version information
Package: php Version: 1:7.0+35ubuntu6 Priority: optional Section: php Source: php-defaults (35ubuntu6) Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 11.3 kB Depends: php7.0 Supported: 5y Download-Size: 2,832 B APT-Sources: http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages Description: server-side, HTML-embedded scripting language (default) PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. . This package is a dependency package, which depends on Debian's default PHP version (currently 7.0).
To install the default PHP version from the Ubuntu software repository, use the command below.
$ sudo apt install php
Install PHP on Ubuntu (5.6, 7.0, 7.1) using PPA
##1. Start the installation on Ubuntu system by adding PPA Different PHP versions - PHP 5.6, PHP 7.0 and PHP 7.1.
$ sudo apt install python-software-properties $ sudo add-apt-repository ppa:ondrej/php
2. Next, follow the steps below to update your system.
$ sudo apt-get update
3. Now install different versions of PHP as shown below.
For Apache Web Server
$ sudo apt install php5.6 [PHP 5.6] $ sudo apt install php7.0 [PHP 7.0] $ sudo apt install php7.1 [PHP 7.1]
For Nginx Web Server
$ sudo apt install php5.6-fpm [PHP 5.6] $ sudo apt install php7.0-fpm [PHP 7.0] $ sudo apt install php7.1-fpm [PHP 7.1]
4. To install For any PHP module, just specify the PHP version and use the autocomplete feature to view all modules as shown below.
------------ 按Tab键自动完成------------ $ sudo apt install php5.6 $ sudo apt install php7.0 $ sudo apt install php7.1
5. Now you can install most of the required PHP modules from the list.
------------ 安装PHP模块 ------------ $ sudo apt install php5.6-cli php5.6-xml php5.6-mysql $ sudo apt install php7.0-cli php7.0-xml php7.0-mysql $ sudo apt install php7.1-cli php7.1-xml php7.1-mysql
6. Finally, verify the default PHP version used on your system like this.
$ php -v
Set the default PHP version in Ubuntu
7. You can use the update-alternatives command to set The default PHP version to be used on the system, after setting it, check the PHP version confirmation as shown below.
------------ 设置默认PHP版本5.6 ------------ $ sudo update-alternatives --set php /usr/bin/php5.6
------------ 设置默认PHP 版本7.0------------ $ sudo update-alternatives --set php /usr/bin/php7.0
------------ 设置默认PHP 版本7.1 ------------ $ sudo update-alternatives --set php /usr/bin/php7.1##8
. To set up will work with Apache web To work with the PHP version of the server, please use the following commands. First use the a2dismod command to disable the current version, then use the a2enmod command to enable your desired version. $ sudo a2dismod php7.0
$ sudo a2enmod php7.1
$ sudo systemctl restart apache2
. After switching from one version to another, you can find your PHP configuration file by running the command below. ------------ PHP 5.6 ------------
$ sudo update-alternatives --set php /usr/bin/php5.6
$ php -i | grep "Loaded Configuration File"
------------ PHP 7.0 ------------
$ sudo update-alternatives --set php /usr/bin/php7.0
$ php -i | grep "Loaded Configuration File"
------------ PHP 7.1 ------------
$ sudo update-alternatives --set php /usr/bin/php7.1
$ php -i | grep "Loaded Configuration File"
Related recommendations: "
PHP Tutorial"This article is about installing different PHP (5.6, 7.0 and 7.1) version method introduction, I hope it will be helpful to friends in need!
The above is the detailed content of How to install different PHP (5.6, 7.0 and 7.1) versions in Ubuntu?. For more information, please follow other related articles on the PHP Chinese website!