Getting Started with PHP 7
Builds for PHP 7.0 and 7.1 are now available from both official and community repositories. In most cases, these new versions can be easily installed using your system’s package manager.
Ubuntu 14.04 and 16.04+
Ondřej Surý provides a PPA for installing PHP 7.0 and 7.1. The latest release can be installed using these commands:
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.0
(Replace 7.0 with 7.1 if desired)
The full list of available packages can be found here: https://launchpad.net/~ondrej/+archive/ubuntu/php/+packages?field.name_filter=php7.0
Debian 8 & 9
Ondřej Surý also provides PHP 7.0 and 7.1 packages for Debian which can be installed using these commands:
sudo apt-get install apt-transport-https lsb-release ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sudo sh -c "echo 'deb https://packages.sury.org/php/ $(lsb_release -sc) main'" >\
/etc/apt/sources.list.d/php.list
sudo apt-get update
sudo apt-get install php7.0
Debian 6 & 7
PHP 7.0 can be installed using the Dotdeb repository:
Add these two lines to your /etc/apt/sources.list file, replacing <distribution> with either squeeze, wheezy, or jessie:
deb http://packages.dotdeb.org <distribution> all
deb-src http://packages.dotdeb.org <distribution> all
Add the GPG key:
wget https://www.dotdeb.org/dotdeb.gpg
sudo apt-key add dotdeb.gpg
Install PHP 7:
sudo apt-get update
sudo apt-get install php7.0
The full list of available packages can be found here: http://packages.dotdeb.org/pool/all/p/php7.0/
CentOS / RHEL
PHP 7 can be installed using the Webstatic Yum repository:
If you’re using CentOS/RHEL 7.x, run these three commands to add the repository and install PHP 7:
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php70w
If you’re using CentOS/RHEL 6.x, run these two commands to add the repository and install PHP 7:
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
yum install php70w
The full list of available packages (including SAPIs and extensions) can be found here: https://webtatic.com/packages/php70/#sapi
Mac OS X
PHP 7 can be installed using homebrew:
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew install php70
Or you can install it via Liip’s php-osx tool:
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0
Windows
PHP 7 distributions for Windows can be found on the windows.php.net website: http://windows.php.net/download#php-7.0
For local development, you could instead use third-party distributions like XAMPP or EasyPHP. Both come with PHP 7, MySQL, and a web server so you can get up-and-running fast.
phpbrew
phpbrew is a wonderful utility which allows you to easily build and switch between different versions of PHP on the same machine. It supports all modern versions of PHP, including PHP 7.
First we need phpbrew to fetch information about available versions:
phpbrew self-update
We can then install PHP 7.0, 7.1, or any other version:
phpbrew install php-7.0.25
phpbrew use php-7.0.25
Docker
Official Docker images for PHP can be found at https://hub.docker.com/_/php/.
docker pull php:latest
Vagrant Image
Rasmus Lerdorf, the creator of PHP, provides a Vagrant box image on his GitHub: https://github.com/rlerdorf/php7dev
It’s based on Debian 8 and is pre-configured to help develop PHP apps and extensions.
Build from Source
PHP.net also offers source packages for the alpha and beta releases which you can download and compile yourself. The source code can be downloaded from https://downloads.php.net/~ab/
Documentation on compiling PHP 7:
- https://wiki.php.net/phpng
- http://www.zimuel.it/install-php-7/
- http://www.hashbangcode.com/blog/compiling-and-installing-php7-ubuntu