Install php7.2 Debian Stretch

As PHP versions 5.6 and 7.0 reach End Of Life you might want to update to something newer and supported, unfortunately the official Debian Stretch repositories don’t have PHP versions 7.1 or 7.2 yet, but with a third-party repository and a bit of fiddling it’s easy to update, and more importantly keep it updated, your server PHP version.
 

Just run as root:


wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list
apt install ca-certificates apt-transport-https
apt update
apt install php7.2 php7.2-fpm php7.2-cli php7.2-intl

 
Caveats:
1) This is a third-party repository you should carefully decide if you trust the owner of the repository or if you want to build it yourself, both options have merits and downsides.
 
2) It doesn’t ship a package named php7.2-xdebug, but if you need this package you can remove and reinstall the php-xdebug package,the official repositories have xdebug version 2.5 which is incompatible with php7.2, but this repository comes with xdebug version 2.6 which it compatible, or you can follow THIS tutorial and build xdebug 2.6 yourself.

Sources

https://www.rosehosting.com/blog/how-to-install-php-7-2-on-debian-9/
https://linuxize.com/post/how-to-install-php-on-debian-9/
https://www.chris-shaw.com/blog/installing-php-7.2-on-debian-8-jessie-and-debian-9-stretch
https://blog.here-host.com/install-php-7-2-debian-9/
https://tecadmin.net/install-php-debian-9-stretch/