How to install php in ubuntu Linux?

If you’re trying to configure PHP into your Ubuntu Linux, you definitely wouldn’t need an explanation about what PHP or Ubuntu is. So, let’s get our geek on and dive in!

There are two ways to install PHP on your Ubuntu.

Before you begin:

Make sure you’re logged in as a user with Sudo privileges.

Route one:

This one is pretty simple. All you need to do is:

Add deb hardy- security main

in your /etc/apt/sources.list

Route two:

This is a little more complex and involves everything from downloading PHP to finally setting it up.

Step 1. Download

If you have tried downloading before, you already know getting PHP for you Ubuntu isn’t as easy as downloading your favorite movies or songs. So, here’s a detailed instruction on how you can obtain the PHP for Ubuntu.

  • First, go to
  • As soon as you open the site, you’ll see a list of packages. Don’t be confused with or hung up on all the packages, scroll down to search package directories.
  • Now, fill the search form.

Keyword: PHP7.4

Distribution: Select your Ubuntu Version

Don’t restrict your search by ticking on Show only the exact matches.

  • Then, click search.

You will find a list of suits that matches your Ubuntu Version.

Find libapache2-mod-php7.4, then click on your Ubuntu version (It’s a link).

  • The link will take you to another page. Look for Download libapache2-mod-php7.4. If you’re using a 64 bit AMD Processor, click on amd64. If you’re using an Intel processor, click on i386.

Step 2. Install

Now, you have to install the PHP. Don’t freak out, it’s shorter and easier than the first step.

  • Start the root terminal.
  • Fire aptitude install php7.4 libapache2-mod-php7.4 command.

 $sudo apt-get install php7.1

  • As it is mandatory for you to have root privilege for installing PHP, you can use su or run it from the root terminal.

 $php -v   

This command will show you the Current PHP Version.

  • Use vi editor or text editor to open the page in the terminal .

 $vi /var/www/html/index.php

  • After that, copy-paste the php info <?php echo phpinfo(); ?> and save the file.
  • Then, read and execute permissions for /var/www and all of its subdirectories and files.

$php /var/www/html/index.php

  • Then, restart the apache webserver with command /etc/init.d/apache2, if you’re using version 2. Change the command according to the version you are using.

Step 3. Test

Now that you have downloaded and installed PHP, it’s time to test it.

To test, open browser type URL, “HTTP://localhost/test.php.

In the browser, you will see PHP info.

If PHP is installed, you’ll get ‘PHP successfully configured’ as an output.

We genuinely hope that this guide was useful to you. Feel free to leave your doubts in the comments section. We would be happy to help.