You can install multiple PHP versions on Ubuntu system and then switch PHP version as per your requirements. You can also configure Apache to run PHP web applciation’s with different-2 PHP versions.


You must have sudo or root privileged account access on Ubuntu 20.04. First of all, open a terminal and update the current packages with the following commands:

Installing PHP on Ubuntu 20.04

PHP installation on Ubuntu systems is pretty straightforward. You just need to add the required PPA and you can install any PHP version on the Ubuntu system. Follow these steps to complete PHP installation on Ubuntu:

Check Active PHP Version

To view the current active PHP version run the following command: Users have installed different PHP version, need to replace 7.4 with required PHP versions.

Change Default PHP Version for CLI

You can use the update-alternatives command to set the default PHP version. Use this tutorial to read more details about switching PHP version for CLI and Apache. The above output shows all the installed PHP versions on your system. Selection number 4 set PHP 8.1 as the default PHP version for the command line.

Uninstall PHP

If any PHP version is no more required, can be removed from the system. That will free the disk space as well as system security. To uninstall any PHP version just type: Also, uninstall all the modules for that version with the following command:


This tutorial helps you to install PHP 8.1, 8.0, 7.4, 7.3, 7.2, or PHP 5.6 on Ubuntu 20.04 Linux system. Additionally provides you instructions to change the default PHP version. You can start building awesome web applications using the PHP programming language. You may also like to use a feature-loaded IDE like Visual Studio Code editor on your Ubuntu system.