How to install PHP 7 on Debian Linux 8.7/7.x [jessie/wheezy]

I wanted to use PHP 7 on Debian 8.x. How do I install and configure PHP 7 on Debian Linux 8.x server? How do I install PHP 7 on Debian Linux 7.x “wheezy” VPS server hosted in cloud?

PHP 7 is a dynamic scripting langauge for delivering applications. You can get 2x faster performance and 50% better memory consumption than PHP 5.6, allowing you to serve more concurrent users without adding any hardware. However, PHP 7 not included with Debian 8.x stable version. In this tutorial, you will learn about installing PHP 7 on Debian 8.7 server. Please note that Debian 9.0 “Stretch” will include PHP 7 by default.

Related: How to install PHP 7 on Ubuntu Linux 14.04 LTS

Steps to install PHP 7 on Debian 8.7

  1. First, remove old PHP 5.6
  2. Configure dotdeb is an extra repository for PHP 7
  3. Install PHP 7
  4. Reconfigure web server
  5. Restart web server

To list your Debian version, enter:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 8.7 (jessie)
Release: 8.7
Codename: jessie

Use the following syntax to save existing config files:
$ sudo tar zcvf /root/etc.backup.tar.gz /etc/

Step #1: Delete old php 5.6 (if installed)

First, list all installed old php 5.x packages, enter:
$ dpkg --list | grep php | awk '/^ii/{ print $2}'
Sample outputs:

Fig.01: Debian Linux list installed PHP packages on the system

To delete old php 5.6 packages, enter:
$ x="$(dpkg --list | grep php | awk '/^ii/{ print $2}')"
$ sudo apt-get --purge remove $x

Sample outputs:

Fig.02: Deleting old php 5.6 packages

Step #2: Configure dotdeb

Dotdeb is an extra repository providing up-to-date packages (such as PHP 7 and more) for your Debian servers. It supports both Debian 8.x “Jessie” and Debian 7.x “Wheezy”.

Configuration for Debian 8.x “Jessie”

Append the following two lines to /etc/apt/sources.list as root user::
$ sudo -s
# echo 'deb jessie all' >> /etc/apt/sources.list
# echo 'deb-src jessie all' >> /etc/apt/sources.list

Save and close the file. Here is my updated file:
$ cat /etc/apt/sources.list
Sample outputs:

Fig.03: Updated /etc/apt/sources.list for Debian 8.x “jessie”.

Configuration for Debian 7.x “Wheezy”

Append the following two lines to /etc/apt/sources.list as root user:
$ sudo -s
# echo 'deb wheezy all' >> /etc/apt/sources.list
# echo 'deb-src wheezy all' >> /etc/apt/sources.list

Save and close the file.

As of 15/Feb/2017 the above instructions for Debian 7.x “Wheezy” are no longer working. Please use following instructions to compile PHP 7 from the source code:
$ sudo apt-get install git
$ cd /tmp
$ git clone
$ cd php-7-debian/
$ ./

It will take some time to download and compile everything. At the end you should see something as follows:

Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/
Installing PHP CLI binary:        /usr/local/php7/bin/
Installing PHP CLI man page:      /usr/local/php7/php/man/man1/
Installing PHP FPM binary:        /usr/local/php7/sbin/
Installing PHP FPM config:        /usr/local/php7/etc/
Installing PHP FPM man page:      /usr/local/php7/php/man/man8/
Installing PHP FPM status page:   /usr/local/php7/php/php/fpm/
Installing phpdbg binary:         /usr/local/php7/bin/
Installing phpdbg man page:       /usr/local/php7/php/man/man1/
Installing PHP CGI binary:        /usr/local/php7/bin/
Installing PHP CGI man page:      /usr/local/php7/php/man/man1/
Installing build environment:     /usr/local/php7/lib/php/build/
Installing header files:           /usr/local/php7/include/php/
Installing helper programs:       /usr/local/php7/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php7/php/man/man1/
  page: phpize.1
  page: php-config.1
/tmp/php-7-debian/php-src/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin
ln -s -f phar.phar /usr/local/php7/bin/phar
Installing PDO headers:           /usr/local/php7/include/php/ext/pdo/

To install PHP 7 on Debian 7.x:
$ sudo ./
Sample outputs:

update-rc.d: using dependency based boot sequencing

You can verify PHP version:
$ /usr/local/php7/bin/php --version
PHP 7.1.1 (cli) (built: Feb 15 2017 18:49:03) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.1, Copyright (c) 1999-2017, by Zend Technologies

All PHP configuration files are stored under /usr/local/php7:


While the Debian init script is added to:


See this page for more info about using PHP 7 on Debian 7.x. The rest of the following instructions are for Debian version 8.x only.

Step #3: Fetch and install the GnuPG key (“jessie” only)

Type the following commands
$ cd /tmp
$ wget
$ sudo apt-key add dotdeb.gpg
$ rm dotdeb.gpg

Refresh apt database to include new packages:
$ sudo apt-get update
Sample outputs:

Get:1 jessie/updates InRelease [63.1 kB]           
Ign stable InRelease                                 
Get:2 jessie InRelease [9,840 B]                   
Hit jessie-updates InRelease                            
Hit stable Release.gpg                               
Get:3 jessie/all Sources [30.0 kB]                 
Get:4 jessie-updates/main amd64 Packages/DiffIndex [5,932 B]
Hit stable Release                                   
Get:5 jessie/updates/main amd64 Packages [313 kB]  
Hit jessie-updates/contrib amd64 Packages               
Hit stable/main amd64 Packages                       
Get:6 jessie/all amd64 Packages [111 kB]           
Get:7 jessie-updates/non-free amd64 Packages/DiffIndex [736 B]
Hit stable/contrib amd64 Packages                    
Get:8 jessie/updates/contrib amd64 Packages [2,506 B]
Hit jessie-updates/contrib Translation-en               
Hit stable/non-free amd64 Packages                   
Get:9 jessie-updates/main Translation-en/DiffIndex [2,704 B]
Get:10 jessie/updates/non-free amd64 Packages [14 B]
Get:11 jessie/updates/contrib Translation-en [1,211 B]
Hit stable/contrib Translation-en                    
Get:12 jessie-updates/non-free Translation-en/DiffIndex [736 B]
Get:13 jessie/updates/main Translation-en [168 kB] 
Hit stable/main Translation-en                       
Get:14 jessie/updates/non-free Translation-en [14 B]
Hit stable/non-free Translation-en                   
Ign jessie/all Translation-en_IN                   
Ign jessie/all Translation-en                      
Fetched 708 kB in 10s (69.8 kB/s)                                             
Reading package lists... Done

Step #4: Install PHP 7 (“jessie” only)

You created a shell variable called $x in step #1. To install equivalent of php5 packages, enter:
$ y="$(sed 's/php5/php7.0/g' <<$x)"
$ echo Old PHP5 packages name: $x
Old PHP5 packages name: libapache2-mod-php5 php-pear php5 php5-cgi php5-cli php5-common php5-fpm php5-gd php5-json php5-mysql php5-readline
$ echo New PHP7 packages name: $y
New PHP7 packages name: libapache2-mod-php7.0 php-pear php7.0 php7.0-cgi php7.0-cli php7.0-common php7.0-fpm php7.0-gd php7.0-json php7.0-mysql php7.0-readline
$ sudo apt-get install $y

Sample outputs:

Fig.04: Installing PHP7 on my Debain 8.7 server

How do I search PHP7 packages (“jessie” only)?

$ apt-cache search php7.0-\*
$ apt-cache search php7.0-\* | grep -i mysql

Sample outputs from 1st command:

libapache2-mod-php7.0 - server-side, HTML-embedded scripting language (Apache 2 module)
libphp7.0-embed - HTML-embedded scripting language (Embedded SAPI library)
php-all-dev - package depending on all supported PHP development packages
php7.0 - server-side, HTML-embedded scripting language (metapackage)
php7.0-apcu - APC User Cache for PHP
php7.0-apcu-bc - APCu Backwards Compatibility Module
php7.0-bcmath - Bcmath module for PHP
php7.0-bz2 - bzip2 module for PHP
php7.0-cgi - server-side, HTML-embedded scripting language (CGI binary)
php7.0-cli - command-line interpreter for the PHP scripting language
php7.0-common - documentation, examples and common module for PHP
php7.0-curl - CURL module for PHP
php7.0-dba - DBA module for PHP
php7.0-dbg - Debug symbols for PHP7.0
php7.0-dev - Files for PHP7.0 module development
php7.0-enchant - Enchant module for PHP
php7.0-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary)
php7.0-gd - GD module for PHP
php7.0-geoip - GeoIP module for PHP
php7.0-gmp - GMP module for PHP
php7.0-igbinary - igbinary serializer for PHP
php7.0-imagick - Provides a wrapper to the ImageMagick library
php7.0-imap - IMAP module for PHP
php7.0-interbase - Interbase module for PHP
php7.0-intl - Internationalisation module for PHP
php7.0-json - JSON module for PHP
php7.0-ldap - LDAP module for PHP
php7.0-mbstring - MBSTRING module for PHP
php7.0-mcrypt - libmcrypt module for PHP
php7.0-memcached - memcached extension module for PHP, uses libmemcached
php7.0-mongodb - MongoDB driver for PHP
php7.0-msgpack - MessagePack serializer for PHP
php7.0-mysql - MySQL module for PHP
php7.0-odbc - ODBC module for PHP
php7.0-opcache - Zend OpCache module for PHP
php7.0-pgsql - PostgreSQL module for PHP
php7.0-phpdbg - server-side, HTML-embedded scripting language (PHPDBG binary)
php7.0-pspell - pspell module for PHP
php7.0-readline - readline module for PHP
php7.0-recode - recode module for PHP
php7.0-redis - PHP extension for interfacing with Redis
php7.0-snmp - SNMP module for PHP
php7.0-soap - SOAP module for PHP
php7.0-sqlite3 - SQLite3 module for PHP
php7.0-ssh2 - Bindings for the libssh2 library
php7.0-sybase - Sybase module for PHP
php7.0-tidy - tidy module for PHP
php7.0-xdebug - Xdebug Module for PHP
php7.0-xml - DOM, SimpleXML, WDDX, XML, and XSL module for PHP
php7.0-xmlrpc - XMLRPC-EPI module for PHP
php7.0-xsl - XSL module for PHP (dummy)
php7.0-zip - Zip module for PHP

How do I install PHP7 packages individually?

Alternatively, you can just install needed PHP7 packages. In this example, install php7, php-fpm, php7-mysql and php7-gd:
$ sudo apt-get install php7.0 php7.0-fpm php7.0-gd php7.0-mysql
Let us check PHP version, run:
php -v
php --version

Step #5: Reconfigure web server and php 7 (“jessie” only)

Your php7 config files are located in /etc/php/7.0/ directory as follows:

  • /etc/php/7.0/apache2/ – PHP 7 with Apache 2
  • /etc/php/7.0/fpm/ – PHP 7 fpm for Nginx/Lighttpd/Apache2 and other server.
  • /etc/php/7.0/mods-available/ – All php ini config file for PHP modules such as gd/mysql/memecached and others.

You need to edit files and configure a web-server as per your setup.

Examples: Configure Lighttpd web-server to use PHP 7

Edit the /etc/lighttpd/conf-enabled/15-fastcgi-php.conf file, enter:
$ sudo vi /etc/lighttpd/conf-enabled/15-fastcgi-php.conf
Append/edit as follows (note updated /run/php/php7.0-fpm.sock path):

fastcgi.server += ( ".php" => 
		"bin-path" => "/usr/bin/php-cgi",
		"socket" => "/run/php/php7.0-fpm.sock",
		"max-procs" => 1,
		"bin-environment" => ( 
			"PHP_FCGI_CHILDREN" => "4",
			"PHP_FCGI_MAX_REQUESTS" => "10000"
		"bin-copy-environment" => (
			"PATH", "SHELL", "USER"
		"broken-scriptfilename" => "enable"

Save and close the file. Restart web-server as per step #6.

Examples: Configure Nginx web-server to use PHP 7

Edit the /etc/nginx/sites-enabled/default file, enter:
$ sudo vi /etc/nginx/sites-enabled/default
First add the following at the top of file:

# Upstream to abstract backend connection(s) for PHP 7.
upstream myphpsevenbackend {
  server unix:/run/php/php7.0-fpm.sock;

Next, locate the server block and update/edit/append as follows:

# Pass all .php files onto a php-fpm/php-fcgi server. #
    index index.php;
    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
                return 404;
# This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in php.ini (default) #
    include /etc/nginx/fastcgi_params;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass myphpsevenbackend;

Save and close the file. Restart web-server as per step #6.

Examples: Configure Apache 2 web-server to use PHP 7 (“jessie” only)

To enable PHP 7.0 FPM in Apache2, enter:
$ sudo a2enmod proxy_fcgi setenvif
Considering dependency proxy for proxy_fcgi:
Enabling module proxy.
Enabling module proxy_fcgi.
Module setenvif already enabled
To activate the new configuration, you need to run:
service apache2 restart

$ sudo a2enconf php7.0-fpm
Enabling conf php7.0-fpm.
To activate the new configuration, you need to run:
service apache2 reload

Restart web-server as per step #6.

Step #6: Restart web server

If you are using lighttpd web-server, enter:
$ sudo systemctl restart lighttpd.service
If you are using Nginx web-server, enter:
$ sudo systemctl restart nginx.service
If you are using Apache 2 web-server, enter:
$ sudo systemctl reload apache2.service

Test your setup

Create a file called test.php in your DocumentRoot (e.g. /var/www/html/test.php):

/* test.php */

Save and close the file. Fire a web-browser and type url:
Sample outputs:

Fig.05: phpinfo() in action displaying info about PHP 7

How do I stop/start/restart php7.0-fpm (“jessie” only)?

The syntax is as follows
$ sudo systemctl stop php7.0-fpm.service
$ sudo systemctl start php7.0-fpm.service
$ sudo systemctl restart php7.0-fpm.service
$ sudo systemctl reload php7.0-fpm.service

A note about php7.0-fpm configuration file (“jessie” only)

  • /etc/php/7.0/fpm/php.ini – PHP 7 configuration file.
  • /etc/php/7.0/fpm/php-fpm.conf – PHP 7 FPM Configuration file.
  • /etc/php/7.0/fpm/pool.d/www.conf – Default pool for PHP 7 FPM. Here you can define user/group, FastCGI request path, process manager and children values, php error file, memory limit and much more.

Whenever you made changes to any one of the above file(s), reload/restart php7.0-fpm.service using the following syntax:
$ sudo systemctl reload php7.0-fpm.service

So there you have it, a PHP 7 enabled and configured on Debian Linux 7.x or 8.x server successfully.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 20 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
20 comments… add one
  • fbg13 Nov 4, 2016 @ 9:48

    I’m on ispconfig, do you know if this is safe to do?
    Like it wont mess with ispconfig configs?

    • 🐧 Vivek Gite Nov 4, 2016 @ 9:53

      No idea. If you decided to do this, make sure keep backups.

  • Cleankod Nov 12, 2016 @ 0:52

    I have used your guide to upgrade my production server’s PHP version from 5 to 7. I had one problem though. You declared an environment variable y= with all previously installed php packages, but with version 5 changed to 7. In my case it caused the php5 to install again. Moreover, it has set itself as a default, overriding php7. Why that happened? Well, phpmyadmin depends on php5 packages. So i guess you should add a notice of some kind for future readers… :)

    Anyway, thanks for a great guide. It has helped me a lot!

  • Hussani Nov 28, 2016 @ 17:27

    Apparently PHP 7 is not supported on DotDeb for Wheezy.
    How you get the packages to update?

  • superdev Dec 12, 2016 @ 23:43

    @Hussani: he did’nt test it, LOL.

    • Burak Feb 15, 2017 @ 16:00

      Then update the article. I wasted my time because of this.

      • 🐧 Vivek Gite Feb 15, 2017 @ 18:33

        I updated the faq. It seems that you can now only install PHP 7 using source code method. See updated page for more info.

  • Francis Dec 17, 2016 @ 18:36

    tosystems@debian:~$ sudo apt install mysql-server-5.5
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:

    The following packages have unmet dependencies:
    mysql-server-5.5 : PreDepends: mysql-common (>= 5.5.53-0+deb8u1) but it is not going to be installed
    Depends: libdbi-perl but it is not going to be installed
    Depends: mysql-client-5.5 (>= 5.5.53-0+deb8u1) but it is not going to be installed
    E: Unable to correct problems, you have held broken packages.

  • enoola Feb 6, 2017 @ 12:38

    Thanks a lot for this great article.
    simple to follow I love it.
    Since I needed to do an upgrade prior to Step4,
    By precaution you can save the list of php5x packaged installed in a file ‘x_var.txt’ :
    # x=”$(dpkg –list | grep php | awk ‘/^ii/{ print $2}’)”
    # echo $x > x_var.txt
    restore it after reboot :
    # x=”$(cat x_var)”
    and move on with step 4 :)

  • Max Feb 12, 2017 @ 8:36

    Great guide! Thank you!

  • SEan Mar 11, 2017 @ 17:55

    Couple things. One the is using a self signed cert so –no-check-certificate is needed for the wget command. Second with letsencrypt there is no good reason for sites to be using self signed certs.

  • Chad Apr 28, 2017 @ 0:12

    I followed all the steps very carefully and yet I have two problems now one of the two presents itself on every site on my box. 1) it tries to download php pages or 2) it shows a blank screen.

    • Chad Apr 28, 2017 @ 0:12

      Debian Jessie

  • Ray Apr 29, 2017 @ 9:36

    Awesome guide! Perfect! I’m impressed with my page loading times with PHP7.0! I’d say more than double as fast (especially my webshop and larger database dependant pages).
    After upgrading to PHP7.0 my Joomla CMS did not work anymore for none of my sites, so I would please like to add the following to make this work again:
    Install SimpleXML (to make Joomla work again):
    php -m Check if SimpleXML is loaded
    apt-get install php7.0-simplexml

  • Tiago Galera Aug 14, 2017 @ 12:08

    Great Job!
    Thanks for share it!
    Best regards!

  • Petr N Sep 20, 2017 @ 15:03

    Excellent guide. Worked for both mine dev & production servers.
    Also, I would mark the Step #1 as optional – It’s nice to keep good old working php version if anything fails.

  • Haifeng Nov 21, 2017 @ 3:23

    Thanks for the great direction.
    Good job!

  • Sid Nov 13, 2020 @ 14:17

    This is the only guide that still works for Debian 8 :)
    Sury and Backports don’t work any more.

  • Johannes Eble Dec 9, 2020 @ 14:16

    Thanks for your tutorial, it’s very helpful.
    However, your replacement in Step #4 (php5->php7) didn’t work at all (maybe a typo since there is no closing brace/”?). Instead this worked and is also much easier to type:

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum