1. 先升级:

sudo apt-get update

2. 然后添加PPA:

sudo add-apt-repository ppa:ondrej/php

 

2.1 If add-apt-repository isn’t found, you can install it by way of the python-software-properties package:

sudo apt-get install python-software-properties

3.Once you get the PPA added, you’ll want to do an update so the packages show up:

sudo apt-get update

At this point, you can install PHP 7.x and any extensions you may want.

sudo apt-get install php7.0 # For PHP 7.0

sudo apt-get install php7.1 # For PHP 7.1 Scary Warning: Installing the php7.x packages will install Apache, even if you have another web server already installed. This is just how the meta package is setup. You can install php7.x-cli and/or php7.x-fpm directly without installing Apache. If you do end up installing Apache and don’t want or need it, just uninstall it.

At this point, you should have PHP 7.x up and running on your server!

4. 查看php7的扩展

sudo apt-cache search php7-*

5. 如果安装过 libapache2-mod-php5,要先卸载 libapache2-mod-php5, 然后安装 libapache2-mod-php7.1

否则phpinfo()输出的php版本还是5.5

Package named php5 or php5.6 is just a meta-package that pulls one of the available web SAPIs (apache2, fpm or cgi). The easiest way how to remove full stack of packages is to remove php5-common and/or php5.6-common package as everything else depends on it, e.g.:

apt-get purge php5-common

The other option would be to use wildcard support in apt-get and do:

apt-get purge 'php5*'

 

Recent Posts