I have installed php 5.6 and and php 7.1 on my Ubuntu 16.04
I know with Apache as my web server, I can do
a2enmod php5.6 #to enable php5
a2enmod php7.1
type this in your command line, should work for all ubuntu between 16.04, 18.04 and 20.04.
$ sudo update-alternatives --config php
and this is what you will get
There are 4 choices for the alternative php (providing /usr/bin/php).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/php7.2 72 auto mode
1 /usr/bin/php5.6 56 manual mode
2 /usr/bin/php7.0 70 manual mode
3 /usr/bin/php7.1 71 manual mode
4 /usr/bin/php7.2 72 manual mode
Press to keep the current choice[*], or type selection number:
Choose the appropriate version