How To Install LAMP Stack In Ubuntu 20.04

Installing LAMP Stack on Ubuntu 20

In our previous LAMP stack articles, we learned how to install LAMP Stack on CentOS 7 and Debian 9. And in this article, we’re going to learn how to install LAMP Stack on Ubuntu 20.04, one of the latest releases of Ubuntu’s distribution. But before we begin, let’s have an overview minimum system requirements for smooth installation.

What Are The Requirements For LAMP Stack?

Requirements technically are based on what you’re going to host. But for a simple WordPress website, we’d take the following specs.

  • 512 MB of RAM
  • 20 GB of minimum space
  • 1 vCore

Time to head for installation.

Installing LAMP Stack On Ubuntu 20.04

Before we begin the installation, we should note that our machine is in the fresh installation phase. To do all this, you need access to the terminal. Access the terminal of your server by learning how to connect to a server using putty.

Step 1 – Updating repo directory & upgrading the packages

It is necessary to update the repository list with it’s latest version and once it’s updated, we will upgrade the package that comes along with the repository list.

sudo apt update && apt upgrade -y

If a GUI popsup in the terminal asking for multiple option, just press Enter on the option “Keep the local version installed”. We do not want to make any big changes with the upgrade, only upgrade the current existing packages and few other updates for seamless functionality of our system.

Step 2 – Installing Apache and basic packages

apt install apache2 wget nano -y

This will install apache, wget and nano text editor. “-y” argument means any prompt that may come during installation is set to “Yes” to install everything properly.

Step 3 – Installing the “M”ySQL system called MariaDB

We will now install MySQL server so that database operations can run smoothly. We will use MariaDB, which is much more efficient in terms of setting it up.

apt install mariadb-server -y

Step 4 – Setting up MariaDB Server

After MariaDB is installed from step 3, we will need to set it up. First we will start the service and then set it up. Note that it is in 2 different lines.

service mariadb start

Now it will ask for a few things. Firstly, it will ask you for entering the MySQL root password. But since it is a fresh installation, press Enter without entering the password and we’ll go on the next step.

Enter current password for root (enter for none):

Now the next step would ask if you want to set up a MySQL root password. Press “Y” for it. Enter the new password.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables...
 ... Success!

Now it will ask for the next few questions. They don’t need much explanation so just follow the instructions as mentioned below.

Remove anonymous users? [Y/n] Y
 ... Success!
Disallow root login remotely? [Y/n] Y
 ... Success!
Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reload privilege tables now? [Y/n] Y

We’re now done setting up MySQL. Let’s make a separate user for MySQL so that we can differ it from the root. To do so, let’s get into MariaDB. To do so, type the following command.


We’ll create a user named “master” and grant it full root access.

GRANT ALL ON *.* TO 'master'@'localhost' IDENTIFIED BY 'P@Ssw0rD2020' WITH GRANT OPTION;

In order to properly protect your root user, make sure you run this command. Change the ‘changeme’ to your desired password.

UPDATE mysql.user SET plugin = 'mysql_native_password', authentication_string = PASSWORD('changeme') WHERE User = 'root';

Now after the user is setup, we will flush privilege.


Exit the session as we’re done with it by using the following commands. If that doesn’t work, just do CTRL + C.


We’ve come this far and successfully installed Apache & MariaDB. Let’s now head towards installing PHP.

Step 5 – Installing PHP

Ubuntu 20.04 primarily comes with PHP 7.4 package so you can install it using apt without making any changes like Debian. Who would not want the latest PHP?

apt install php php-cli php-fpm php-json php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath -y

Now you may see a message prompting you to enable the PHP packages we installed. It’s simple. Run the following command.

a2enmod proxy_fcgi setenvif
a2enconf php7.4-fpm

And a quick restart.

service apache2 restart

Step 6 – Testing PHP

Let’s test the PHP as we’re done installing it. To do so, we’ll first have to restart the webserver as we didn’t do it after post-installation. To do so, run the following command.

service apache2 restart

We’ve successfully restarted Apache. Now let’s test PHP. To do so, we’d need to go to the directory where the website files would be located. Type the following command to head there.

cd /var/www/html

Let’s put some phpinfo() file.

nano phpinfoyoudontwanttoknow.php

And paste this.


Now CTRL + X, then press Y asking to save then press enter for filename.

Now replace your server IP and goto this URL in your web browser.


You should delete the file once confirmed if PHP is working. Delete it by doing this command

rm -rf phpinfoyoudontwanttoknow.php


I agree this is easy to install, just a little big and time-consuming. But… Not actually. What if instead of waiting for hours you could install this within 10 minutes? Yes, it’s possible with Shadow Hosting’s Power VPS Hosting plan range. Purchase one and even with the smallest plan of just $10, it would install within 10 minutes. Yea, no shit. For real.

About Manal Shaikh 25 Articles
Manal Shaikh, the Founder of Shadow Networks International and CEO/Chairman of Shadow Hosting International. A cybersecurity analyst, network analyst and a web administrator.

Be the first to comment

Leave a Reply

Your email address will not be published.


CommentLuv badge