How to Install PHP on Ubuntu 20.04? Step-by-step Easy Guide

PHP is a simple, secure, flexible, and efficient open-source language.

Standing for PHP Hypertext Preprocessor, it is the most used programming language worldwide.

Able to integrate into HTML, PHP handles the connection between your web pages and databases.

After installing Apache as a web server, and MySQL as a database system.

The scripting language, PHP, will process the code to display dynamic content to users.

By the end of this PHP tutorial

  • You’ll be able to install PHP on Ubuntu 20.04 and in less than 7 minutes!

PHP tutorial requirements

Tools required to install PHP

Step 1: Update package repository

First, always update Ubuntu’s package repository.

Why?

Because doing so will:

  • Protect your software, while shortening your future updates time
  • Always get you the latest versions of what you want to install.

You’re probably wondering how to update your package repository by now.

Simply, type the following command into your terminal and press ENTER.

  • sudo apt update

Then, put in your password and let Ubuntu do the magic work.

Don’t forget to check our tutorial on what is Ubuntu Linux and how to install it.

Step 2: Install PHP on Ubuntu

Installing PHP is a straightforward task.

Just, copy the below command and paste it into your terminal.

  • sudo apt install PHP

Press Y to confirm the latest PHP download and install.

Step 3: Verify PHP installation on Ubuntu

Coming up, time to verify the PHP version after the installation.

Put in the command:

  • php -v

Well, you can see that, by the time of writing this article, the latest PHP version is 7.4.3

How to Install PHP on Ubuntu 20.04? Master the basics with this step-by-step "pictures included" guide, in less than 7 minutes! Click To Tweet

Step 4: Install PHP with Apache

Did you know that it is possible to install PHP using Apache as well?

All you have to do is put in the following command:

  • sudo apt install libapache2-mod-php
Installing PHP using Apache via Ubuntu cmd

For the changes to take effect immediately, you need to restart Apache using the given command:

  • sudo systemctl restart apache2

Next, check and verify the Apache PHP module status by using the command:

  • sudo systemctl status apache2

Now that it’s up and running, you are on the right track!

Step 5: Install PHP extensions on Ubuntu 20.04

To get a list of PHP extensions, you can enter the following command

  • sudo apt install php-

Afterward, press the tab button on your keyboard twice, followed by Y, for a complete extensions list

For example, to install the cas extension, the command you need to enter would be:

  • sudo apt install php-cas

The system will ask for the needed additional space to install the extension.

Press “y” to accept the process.

Momentarily, it will begin to download and install the extension you picked up.

This is the way you can download and run any of the available PHP extensions.

Installing one of the PHP Ubuntu extensions

Step 6: Test your PHP process

To test the configuration of your web server for PHP processing.

Create a new file named info.php inside var/www/html with the following command:

  • sudo nano /var/www/html/info.php

With the code:

<?php

phpinfo();

Create a new file inside directory
  1. Save the file
  2. Head over to your browser
  3. Browse the server’s IP address http://your_server_ip/info.php.

You will get the following webpage.

ServerHub to the rescue

You can do it yourself, but you don’t have to!

Wave us hello at [email protected] and let us guide you freely to your upcoming website.

Additionally, with 100% Uptime, 24/7 support, and 40GB interface connectivities.

ServerHub spans 9 locations and offers custom quotes

Check out our amazing deals starting from $5 a month!

Final thoughts

That was the simplest-full guide to master the PHP basics on Ubuntu 20.04.

I’m sure that by now, you are a PHP professional yourself.

With learning how to install PHP, PHP extensions, and integrating them with Apache.

Let us discuss your thoughts and questions in the comments below so we can brainstorm, together!

This tutorial is a part of the LAMP stack guide series.

Check out the rest of the series:

How to install the latest Ubuntu Linux? Beginner’s guide

How To Install Apache On Ubuntu? The Comprehensive Guide

How To Install MySQL On Ubuntu? The Proven 2021 Guide

What’s your Reaction?
+1
3
+1
1
+1
0
+1
0
+1
0
+1
0
+1
0

Leave a Reply

Your email address will not be published. Required fields are marked *