Upgrading from PHP 5 to PHP 7 with Apache or Nginx

The version 7 of PHP aims for a performance with a 64-bit compatibility, an execution speed two times faster than the original one and a RAM usage cut by two-thirds.

Although PHP 7.0 ships by default with Debian 9, a manual upgrade is mandatory for the previous distributions.
Prior to any significant manipulation, we recommend that you backup your server (if running a VM, by doing a snapshot for example).

Below are the steps to upgrade your PHP version on Debian 8 (Jessie):

Installation of the dotdeb repository

Since Debian versions prior to 9 do not ship PHP 7.0, we need to add the dotdeb repository to the system:

Removal of PHP 5

Before installing PHP 7, we first stop and uninstall PHP 5 :

Installation of PHP 7

The PHP 7 installation differs depending if your server runs Nginx or Apache :

Now we can check your PHP version with the following command :

Expected output :


As for the installation step, the PHP7 configuration differs depending if you use Nginx or Apache.
With Apache, the PHP module (libapache2-mod-php7.0) is automatically activated whereas on Nginx (php7.0-fpm), the PHP-FPM socket’s path is updated from /var/run/php5-fpm.sock to /run/php/php7.0-fpm.sock.
Hence, it is mandatory to fix your configuration :

The configuration is now complete, it is important to know that the PHP configuration files are located in /etc/php/7.0/fpm for Nginx + PHP-FPM-based installation, whereas they are located under /etc/php/7.0/apache2 for an Apache-based setup.