How to install PHP 7.2 on Ubuntu

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php7.2

Set PHP5.6 as default version:

$ sudo update-alternatives –set php /usr/bin/php5.6
Alternatively, you can run the following command to set which system wide version of PHP you want to use by default.

$ sudo update-alternatives –config php
Enter the selection number to set it as default version or simply press ENTER to keep the current choice.