Linux

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

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! Share on X

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

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.

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();

  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 support@serverhub.com 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

serverhub

View Comments

  • It's really a nice and helpful piece of information. I am happy that you shared this useful info with us.
    Please keep us up to date like this. Thanks for sharing.

  • Very great post. I just stumbled upon your weblog and wanted to mention that I've truly enjoyed browsing your weblog posts.
    After all I'll be subscribing to your feed and I am hoping you write once more soon!

Recent Posts

Overview of Proxmox VE: Open-source Virtualization Management Platform

Overview of Proxmox VE: Open-source Virtualization Management Platform Proxmox Virtual Environment (VE) is an open-source…

2 days ago

Comprehensive Guide to Oracle, Microsoft SQL Server, PostgreSQL, and MongoDB: Download, Install, and Configure

Introduction to Oracle Database Oracle Database is a widely adopted relational database management system (RDBMS)…

3 weeks ago

Comprehensive Guide to MySQL: Download, Install, and Configure on Ubuntu and macOS

Introduction to MySQL MySQL is one of the most widely used open-source relational database management…

2 months ago

Deep Learning Applications: Factors to Consider in Choosing the Best Server

Deep learning is a type of artificial intelligence that teaches computers to learn from large…

3 months ago

Comprehensive Guide to OpenSSH: Secure Connectivity for Remote Login

OpenSSH or Open Secure Shell is a powerful suite of tools that provides secure remote…

5 months ago

Mastering VMware ESXi: An Ultimate Guide to Virtualization

Virtualization has become a cornerstone of modern IT infrastructure in today's digital era. Among the…

5 months ago

This website uses cookies.