Currently, there are three supported versions of PHP, i.e. PHP 5.6, 7.0, and 8.0. Meaning PHP 5.3, 5.4, and 5.5 have all reached the end of life; they are no longer supported with security updates
To install the default PHP version from the Ubuntu software repositories, use the command below.
To install different versions of PHP – PHP 5.6, PHP 7.x and PHP 8.0 on the Ubuntu system use the below commands.
$ sudo apt install python-software-properties
$ sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
Install different supported versions of PHP as follows.
In Apache webserver
$ sudo apt install php5.6
$ sudo apt install php7.0
$ sudo apt install php7.1
$ sudo apt install php7.2
$ sudo apt install php7.3
$ sudo apt install php7.4
$ sudo apt install php8.0
In Nginx Web Server
$ sudo apt install php5.6-fpm
$ sudo apt install php7.0-fpm
$ sudo apt install php7.1-fpm
$ sudo apt install php7.2-fpm
$ sudo apt install php7.3-fpm
$ sudo apt install php7.4-fpm
$ sudo apt install php8.0-fpm
Finally, verify your default PHP version used on your system like this.
$ php –v
Set Default PHP Version in Ubuntu
Set the default PHP version to be used on the system with the update-alternatives command.
sudo update-alternatives --set php /usr/bin/php5.6
sudo update-alternatives --set php /usr/bin/php7.0
sudo update-alternatives --set php /usr/bin/php8.0