Ubuntu 18.04 comes with php 7.2, and some php applications might still fail with php 7.2 .Therefore, in some cases, it might be sensible to have both php 7.0 and php 5.x, so that you can choose which version to use for your needs at any time. Or even better, 7.1. You need to add a new repository to have other versions of php available, and you will require the equivalent branch for a patched apache2 that will work with the other php version repository.
You can do so with:
{CODE(colors="shell")}
xavi@computer# sudo su
root@computer# add-apt-repository ppa:ondrej/php
root@computer# add-apt-repository ppa:ondrej/apache2
root@computer# apt-get update
root@computer# apt-get install php5.6 php5.6-mysql php-gettext php5.6-mbstring php-xdebug libapache2-mod-php5.6 php5.6-curl php5.6-gd php5.6-mcrypt php5.6-xml php5.6-xmlrpc libphp5.6-embed php-memcache php5.6-intl php5.6-zip php5.6-sqlite3 php5.6-zip
root@computer# apt-get install php7.1 php7.1-mysql php-gettext php7.1-mbstring php-xdebug libapache2-mod-php7.1 php7.1-curl php7.1-gd php7.1-mcrypt php7.1-xml php-xml-parser php7.1-xmlrpc libphp7.1-embed php-memcache php7.1-intl php7.1-zip php7.1-sqlite3 php7.1-zip
root@computer# apt-get install php7.2 php7.2-mysql php-gettext php7.2-mbstring php-xdebug libapache2-mod-php7.2 php7.2-curl php7.2-gd php7.2-xml php7.2-xmlrpc libphp7.2-embed php-memcache php7.2-intl php7.2-zip php7.2-sqlite3 php7.2-zip
root@computer# apt-get install php7.3 php7.3-mysql php-gettext php7.3-mbstring php-xdebug libapache2-mod-php7.3 php7.3-curl php7.3-gd php7.3-xml php7.3-xmlrpc libphp7.3-embed php-memcache php7.3-intl php7.3-zip php7.3-sqlite3 php7.3-zip
root@computer# apt-get install php7.4 php7.4-mysql php-gettext php7.4-mbstring php-xdebug libapache2-mod-php7.4 php7.4-curl php7.4-gd php7.4-xml php7.4-xmlrpc libphp7.4-embed php-memcache php7.4-intl php7.4-zip php7.4-sqlite3 php7.4-zip
{CODE}
Eventually Installing both php5.6 & php7.* resulted in a lot of complaining from apt and lots of conflicts. The first suggested resolution was to remove all the stock php5 packages so that PHP 5.6 could be installed - so I just accepted the first suggestion.
The config files are all in /etc/php/5.6 and /etc/php/7.* respectively - inside here is where you can configure which extensions are loaded, set the ini settings, and everything else for each version in isolation.
So to switch from php 5.6 to php 7.2 you need to do two things:
{CODE(colors="shell")}
# For php in web apps
user@computer:/# sudo a2dismod php5.6; sudo a2enmod php7.2; sudo service apache2 restart
# For php-cli in the command line
user@computer:/# sudo ln -sfn /usr/bin/php7.2 /etc/alternatives/php
user@computer:/# php -v
# PHP 7.2.x (...)
# Copyright (c) 1997-2016 The PHP Group
# Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
{CODE}
or from php7.2 to php5.6:
{CODE(colors="shell")}
# For php in web apps
user@computer:/# sudo a2dismod php7.2 ; sudo a2enmod php5.6 ; sudo service apache2 restart
# For php-cli in the command line
user@computer:/# sudo ln -sfn /usr/bin/php5.6 /etc/alternatives/php
user@computer:/# php -v
# PHP 5.6.21-1+donate.sury.org~xenial+2 (cli)
# Copyright (c) 1997-2016 The PHP Group
# Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
# with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
{CODE}
From the commandline, I have both php5.6 and php7.2 available as commands. I also still have a php command - look in /etc/alternatives to see that it symlinks to a particular version of PHP cli*. You can also quickly check which yours is using by running php -v.
Remember that php.ini and other files with settings are not in /etc/php5 anymore but in /etc/php/__version__/