# PHP 7 安装

## PHP 7 安装

### [CentOS](https://www.centos.org/) 或 [RHEL](https://www.redhat.com/en/technologies/linux-platforms/enterprise-linux) 推荐使用 Yum 安装

* PHP 5.6 版本: [PHP 5.6 on CentOS/RHEL 7.2 and 6.8 via Yum](https://webtatic.com/packages/php56/)
* PHP 7.0 版本:[PHP 7.0 on CentOS/RHEL 6.8 and 7.3 via Yum](https://webtatic.com/packages/php70/)
* PHP 7.1 版本: [PHP 7.1 on CentOS/RHEL 6.8 and 7.3 via Yum](https://webtatic.com/packages/php71/)

> 注意:5.6 7.0 7.1的源其实是一个

### [Ubuntu](http://www.ubuntu.org.cn/) 推荐使用apt -get 安装

> php7.0不支持Ubuntu 12.04版本及以下版本
>
> 注意:5.6 7.0 7.1的源其实是一个
>
> <https://launchpad.net/~ondrej/+archive/ubuntu/php-qa>

```
$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:ondrej/php
$ sudo add-apt-repository ppa:ondrej/php-qa
$ sudo apt-get update

# 安装php5.6
$ sudo apt-get install -y php5.6

# 安装php7.0
$sudo apt-get install -y php7.0

# 安装php7.1
$sudo apt-get install -y php7.1
```

#### 资料

* [How to Install PHP 5.6 or PHP 7.1 on Ubuntu 16.04, 14.04 or 12.04 using PPA](https://tecadmin.net/install-php5-on-ubuntu/#)
* [install-php-7-on-ubuntu](http://tecadmin.net/install-php-7-on-ubuntu/)
* [使用PPA在Ubuntu上安装php 5.4\~php 5.6 , php7](http://www.cnblogs.com/toughlife/p/5479325.html)
* [How to Install and Configure PHP 7.0 or PHP 7.1 on Ubuntu 16.04](https://www.vultr.com/docs/how-to-install-and-configure-php-70-or-php-71-on-ubuntu-16-04)

## PHP 各版本切换

### Ubuntu

假设您使用了以上方式在Ubuntu环境下安装了

* php5.6
* php7.0
* php7.1

> 以下例子只做了php5.6 与php7.0之前的切换, php7.1之间的切换雷同

```
从 php5.6 切换到 php7.0 :

# Apache:
$ sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart

# CLI:
sudo update-alternatives --set php /usr/bin/php7.0
sudo update-alternatives --set phpize /usr/bin/phpize7.0
sudo update-alternatives --set php-config /usr/bin/php-config7.0

﻿从 php7.0 切换到 php5.6 :

# Apache:
$ sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart

# CLI:
sudo update-alternatives --set php /usr/bin/php5.6
sudo update-alternatives --set phpize /usr/bin/phpize5.6
sudo update-alternatives --set php-config /usr/bin/php-config5.6

﻿从 php7.0 切换到 php7.1 :

# Apache:
sudo a2dismod php7.0 ; sudo a2enmod php7.1; sudo service apache2 restart

# CLI:
sudo update-alternatives --set php /usr/bin/php7.1
sudo update-alternatives --set phpize /usr/bin/phpize7.1
sudo update-alternatives --set php-config /usr/bin/php-config7.1
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://php7.shujuwajue.com/php-7-an-zhuang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
