How To Install Multiple PHP Version on Ubuntu 20/18 and 16


You should already have Apache installed and serving web pages before following this guide.

For this tutorial, we are using the PHP 5.6, PHP 7.0/7.1/7.2 and PHP 7.3 to configure with Apache web server and system.
To use the multiple PHP versions, we will use PHP FPM and FastCGI. Let’s install the following packages on your system.
You can change the php version name as per your need during installtion

Step 1. Add Repository and required packages

Let’s begin by updating the package lists.

sudo apt update

For Ubuntu 20.04 and 18.04 users, install libapache2-mod-fcgid.

For Ubuntu 16.04 users, install libapache2-mod-fastcgi.

sudo apt install libapache2-mod-fcgid -y
sudo apt install libapache2-mod-fastcgi

On Ubuntu 20/18.04 install and add apt repository

On Ubuntu 16.04 install and add apt repository

sudo apt install software-properties-common -y && sudo add-apt-repository ppa:ondrej/php
sudo apt install python-software-properties -y && sudo add-apt-repository ppa:ondrej/php

Press ENTER when prompted to add the repository.

Step 2: Next, update the system as follows.​
sudo apt update
Step 3: Now install different supported versions of PHP as follows.

Change the php version as per your requirement 5.6 to latest version.

sudo apt install php5.6
sudo apt install php7.0 
sudo apt install php7.2
Step 4: Now you can install most required PHP modules from the list.

Modules which is most required:

cli, common, xml, xmlrpc, mysql, fpm, mbstring, curl, gd, imap, opcache, soap, zip and intl.

sudo apt install php5.6-cli  php5.6-common php5.6-xml  php5.6-xmlrpc php5.6-mysql  php5.6-fpm php5.6-curl php5.6-mbstring php5.6-gd php5.6-dev php5.6-imap  php5.6-opcache php5.6-soap php5.6-zip php5.6-intl -y 
sudo apt install php7.0-cli  php7.0-common php7.0-xml  php7.0-xmlrpc php7.0-mysql  php7.0-fpm php7.0-curl php7.0-mbstring php7.0-gd php7.0-imagick  php7.0-dev php7.0-imap  php7.0-opcache php7.0-soap php7.0-zip php7.0-intl -y
sudo apt install php7.2-cli  php7.2-common php7.2-xml  php7.2-xmlrpc php7.2-mysql  php7.2-fpm php7.2-curl php7.2-mbstring php7.2-gd php7.2-imagick  php7.2-dev php7.2-imap  php7.2-opcache php7.2-soap php7.2-zip php7.2-intl -y
Step 5: Finally, verify your default PHP version used on your system like this.
sudo php -v
Step 6: To set the PHP version that will work with Apache web server, use the commands below.

Example: Switch From PHP 5.6 => PHP 7.2 

sudo a2dismod php5.6 #disable current version

sudo a2enmod php7.2  #enable the version that required

sudo service apache2 restart  #apache restart required

To verify the php version create the info.php file in /var/www/html location or a documentroot of a website.

Place the below code inside the info.php file and save it.

<?php phpinfo(); ?>

Hit the url in browser ex: 

Step 7: You can set the default PHP version to be used on the system with the update-alternatives command, after setting it, check the PHP version to confirm as follows.

example: now we are switching between 7.2 to 7.0

sudo update-alternatives --set php /usr/bin/php7.0 && php -v
Step 8: After switching from one version to another, you can find your PHP configuration file, by running the command below.
php -i | grep "Loaded Configuration File"

Using the above tutorial you have learned how to install multiple php version and changed the default version.

Please Drop Comment if you faced any issue at any point, I will try to help asap.
100% LikesVS
0% Dislikes


  • Hello. This article was really remarkable, especially because I was browsing for thoughts on this matter last Monday. Andee Tome Maida

  • Brilliant. Thank you. I love it when a lightbulb moment is shared Gabbi Alvie Church

  • I was suggested this blog by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my problem. Iseabal Sigfried Jaeger

  • Wonderful article! We will be linking to this particularly great content on our website. Keep up the great writing. Judith Davidde Brockwell

  • Thanks a lot for the post. Really thank you! Much obliged. Gladys Tann Allianora

  • Dead written written content , appreciate it for selective information . Mariana Portie Barcellona

  • As I website owner I believe the content material here is very superb, thanks for your efforts. Pollyanna Willi Dollie Jo-Ann Vinny Edme

  • Hi there. I discovered your blog by the use of Google whilst looking for a comparable topic, your site came up. It seems to be great. I have bookmarked it in my google bookmarks to come back then. Suzanne Hernando Stenger

  • I like the helpful information you provide in your articles.

    I will bookmark your blog and check again here regularly. I’m quite certain I’ll learn many new stuff right
    here! Best of luck for the next!

  • This post is really a pleasant one it helps new the web users, who are wishing for blogging.

  • Hello There. I found your weblog the usage of msn. This is a very smartly written article.

    I’ll be sure to bookmark it and come back to learn extra of your helpful info.
    Thanks for the post. I’ll certainly return.

Comments are closed.