How To Update PHP 7.0 to PHP 7.2 on Debian Easily

More than a year a go, I wrote about how to upgrade PHP 5.6 to PHP 7.0.

Now, PHP 7.0 will reached the end of its critical support through December 2018. After that date PHP community will no longer provides support for bugs. Following to PHP 7.0, PHP 7.1 will be put under discontinued support next year.

Also, since dotdeb dropped support for PHP 7.1 and later so we will use another package provided by Ondřej Surý’s.

Let’s get into the action.

Installing Ondřej’s Package

sudo apt 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

then, install php 7.2

sudo apt-get install php7.2-fpm

installing php7.2-fpm will automatically install another dependencies, so don’t bother by installing them one by one.

Install php-mysql

sudo apt-get install php7.2-mysql

Configuring Nginx Server Block

You can change the block in every domain configuration if you want to use multiple php install. To change a domain to use PHP 7.2 open the server block:

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

change

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

to

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

Start PHP 7.2 and Shutdown PHP 7.0

sudo etc/init.d/php7.2-fpm start

If you want to shutdown the PHP 7.0

sudo etc/init.d/php7.0-fpm stop

Restart Nginx

sudo /etc/init.d/nginx restart

Now your sites running under PHP 7.2.

Remove Old PHP 7.0 Packages (optional)

If you are ready to move on, let’s proceed on the removal:

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

Cheers!

Linux, PHP

Any idea? Fill the comment below

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