How to Install Linux, Apache, MySQL and PHP (LAMP) on a Ubuntu 20.04 Cloud Server

Verified and Tested 06/12/2021

Introduction

In this How-To, we install LAMP on an Ubuntu 20.04 Cloud Server. LAMP is a simple software bundle of 4 components, Linux, Apache, MySQL, and PHP. Linux is the platform’s core; in this case, we are using Ubuntu 20.04 LTS. Apache is the webserver; most of the web servers globally are running Apache MySQL, a database management system developed by Oracle. PHP is an extremely popular programming language widely used in web development. Altogether this forms LAMP or LAMP stack.

Prerequisites

A server with Ubuntu 20.04  installed. Get a reliable VPS from Atlantic.Net if you do not have one.

Installing LAMP on Ubuntu 20.04

Before we begin the installation, your system must be up to date; you can do so with the following command:

apt-get update

Once updating, we can get to the first step of making a LAMP stack by installing Apache.

Installing Apache on Ubuntu 20.04

Install Apache by running the following command:

apt-get install apache2

Hit enter when it asks, “Do you want to continue?” during the install.

After the install, you can check to see if Apache is running by running the command:

systemctl status apache2

Also, you can verify if all is working by opening your browser and going to http://youripaddress

If you do not know your IP address, you can run the following command:

ip addr show eth0
Display IP address

In our case, we would put http://69.87.216.72 in your browser’s address bar and get the following page:

The default page for Apache on Ubuntu 14.04

The default page for Apache on Ubuntu 20.04

Installing MySQL on Ubuntu 20.04

Install MySQL with the following command:

sudo apt-get install mysql-server libapache2-mod-php php-mysql

After installing MySQL server, secure the MySQL server with the following command:

mysql_secure_installation

Note: You will be prompted with a series of questions. Just type N for the change root password and Y for yes on all of the rest; see the screenshot below:

An example of what mysql_secure_installation looks like

An example of what mysql_secure_installation looks like

Verify that MySQL is running with the following command:

systemctl status mysql

Installing PHP on Ubuntu 20.04

Install PHP with the following command:

apt-get install php

Create a test PHP file called info.php in /var/www/html/. In this how-to, we will be using the text editor nano with the following command:

nano /var/www/html/info.php

Insert the following code in the text editor, then save and exit:

<?php
phpinfo();
?>

Since we made changes, we need to restart Apache so that the changes take effect:

systemctl restart apache2

Test your page in your browser with the following hyperlink changed with your IP address:

http: //youripaddress/info.php

Display PHP information

Congratulations! You have just installed LAMP on your Ubuntu 20.04 Server. Thank you for following this How-To on installing LAMP; please check back for more updates.

Learn more about our VPS hosting services and VPS hosting price.

Award-Winning Hosting Solutions & Services

Simple, Fast, Reliable Server Hosting