Upgrade PHP 5.6 to PHP 7 on Nginx / Debian Jessie

Upgrade PHP 5.6 to PHP 7 on Nginx / Debian Jessie

Last Updated: June 27, 2020 | Reading Time: 2 minutes

With recent updates, WordPress has increased it server requirement from PHP 5.6 to PHP 7. I think it is the best time to upgrade PHP to follow the requirement. FYI, Most of my servers are running based on Debian Jessie.

Uninstall old PHP

If your server freshly installed, jump to next step.

I prefer to uninstall old PHP as most of my sites are running WordPress.

List all PHP packages installed:

~# dpkg --list | grep php | awk '/^ii/{ print $2}'

you will see the list of packages related to PHP, if you sure to do this let’s go on to removal process:

~# x="$(dpkg --list | grep php | awk '/^ii/{ print $2}')" [press enter]
~# sudo apt-get --purge remove $x

Install PHP7

Add repository:

~# sudo echo 'deb http://packages.dotdeb.org jessie all' >> /etc/apt/sources.list
~# sudo echo 'deb-src http://packages.dotdeb.org jessie all' >> /etc/apt/sources.list

Install GnuPG key:

~# wget https://www.dotdeb.org/dotdeb.gpg
~# sudo apt-key add dotdeb.gpg

Update local package:

~# sudo apt-get update

Install PHP7:

~# sudo apt-get install php7.0-fpm

Install PHP7-MySQL:

~# sudo apt-get install php7.0-mysql

Configuring Nginx Server Block

Next part is to configuring Nginx server block, the config file(s) location may vary depending on admin’s preferences.

~# sudo vi /etc/nginx/site-available/domain.co.id

Comment old config or delete it, add new path module:

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

Restart Nginx:

~# /etc/init.d/nginx restart

Start PHP7-FPM:

~# /etc/init.d/php7.0-fpm start


~# php -v
PHP 7.0.17-1~dotdeb+8.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.17-1~dotdeb+8.1, Copyright (c) 1999-2017, by Zend Technologies

or, add this to a blank .php file:

<?php phpinfo(); ?>

then access it using your web browser. And try to run your WordPress website now.


I feel that sites are under PHP 7 significantly runs faster. I didn’t do a measured test but, here the benchmark PHP 7 vs previous versions.


You might need to install php-gd to enable image resizing for WordPress:

sudo apt-get install php7.0-gd

These PHP module packages also required:

sudo apt-get install php7.0-curl
sudo apt-get install php7.0-xml

I updated the PHP 7.0 to PHP 7.2

Leave a Comment


No comments yet. Why don’t you start the discussion?

    Any idea? Fill the comment below

    This site uses Akismet to reduce spam. Learn how your comment data is processed.