Install Php 7 And Extra Modules On Debian Based Distros

Upgrade your LEMP stack from PHP 5.x to PHP 7 on Debian distributions

Rodrigo Queiroz
09 Oct 2016
  • 2 min read
  • 121
  • 50
  • 200

This is a short yet useful tutorial if you find yourself stuck when installing PHP 7 on most Debian based distributions, specially Ubuntu which does not include PHP 7 (stable by default).

Installing PHP 7 on vanilla Debian based Distributions

Unfortunately PHP 7 is not available out of the box on most Debian based distributions such as Ubuntu, so we’ll have to add a PPA to be able to install it:

Assuming you have root privileges:

apt-add-repository ppa:ondrej/php -y
apt-get update

Then install PHP 7 and most required extensions:

apt-get install -y php7.0-common php7.0-cli php7.0-fpm php7.0-curl php7.0-sqlite3 php7.0-json php7.0-tidy php7.0-mysql php7.0-mbstring php7.0-xml php7.0-gd

Check if you have PHP 7 installed:

php -v

Output:

PHP 7.0.11-1+deb.sury.org~trusty+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.11-1+deb.sury.org~trusty+1, Copyright (c) 1999-2016, by Zend Technologies

Now let's update the LEMP stack to PHP 7

This part I assume you already have a LEMP Stack (Linux, NGINX, MySQL, PHP) installed with possibly PHP 5.x running.

To update LEMP to use the latest PHP 7, we have to edit /etc/nginx/sites-available/default and replace:

fastcgi_pass unix:/var/run/php5-fpm.sock;

with

fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

then restart NGINX

service nginx restart

In case you have a site-specific configuration and wish to udpate; locate the file in /etc/nginx/sites-available/sitename.dev and replace the same line as above, which will be inside location ~ \.php$ {.

You should now be running PHP 7 with NGINX. Good luck and happy coding.