How To Install [LAMP] Linux, Apache, MySQL & PHP on Ubuntu 18.04.2 Digital Ocean Server

Tutorial to install & deploy the LAMP Server on Ubuntu 18.04.2 in Digital Ocean

LAMP Server Digital Ocean

Install LAMP on Ubuntu 18.04.2: Ubuntu is one of the most used server-side operating systems. This is due to the ease interface and it has many features that can be implemented on the server side too.

The “LAMP” stack is a group of software that pre-installed on the server to run the dynamic web apps on the server. The LAMP can be expanded as “Linux, Apache, MySQL & PHP”. The Linux is the base operating system software, Apache is the web server which handles the request from inside and outside the server, MySQL is the database for the server & finally, The PHP is the programming language which the web apps based on the PHP language.

This article is suitable only for Ubuntu 18.04.2 version. 

Main Index:


In this article, You will lean, how to install the LAMP stack on Ubuntu 18.04.2 server through the step by step installing method and by through the “one-click app” installation method.

If you don’t have the Digital ocean account. Create the new Digital Ocean Account and get “100$” free credit to run web apps.

Install LAMP on Ubuntu 18.04.2 – Step by Step Method:

Just follow the below steps to install the LAMP stack in Ubuntu 18.04.2 server.

Jump To:

Install Ubuntu 18.04.2 on Digital Ocean:

Follow the article to download and install ubuntu 18.04.2 on Digital Ocean server.

Install Apache Web Server:

The Apache web server is one of the most commonly used servers in the world. This server is more reliability and so most of the web apps using Apache as the web server.

Install Apache from Ubuntu’s Package manager:

sudo apt update
sudo apt install apache2

Type the code in console of your server and click enter button. It will ask you the server password and now “Enter” the password to continue the installation. Now it will ask you question sonsuming the space of your server and press “Y” & click “Enter” button.

The installation process will start and the Apache server will installed on your PC.

Modifying the Firewall to allow Web Traffic:

You need to follow the below instructions to enable the UFW firewall. This UFW firewall will permit the traffic from HTTP & HTTPS request.

sudo ufw app list

If you enter the above command, you will get the following output.

Available applications:

Apache Apache Full

Apache Secure


The “Apache Full” profile will enables the traffic from 443 & 80 ports.

sudo ufw app info “Apache Full”

The output will be:

Profile: Apache Full

Title: Web Server (HTTP,HTTPS)

Description: Apache v2 is the next generation of the omnipresent Apache web server.

Ports: 80,443/tcp

Now you need to enable the incoming traffic through the port 80 & 433.

sudo ufw allow in “Apache Full”

That’s it, The Apache web server has been installed in your server. To check this, you need to enter the IP address of your server in the browser as shown in below:

http:// Your IP Address

You will able to see the Apache Default page on your IP address on the browser.

Check this too  How to Enable Suspend Button in Ubuntu 18.04, 19.04 & 19.10?
Apache Default Page
Apache Default Page

Installing MySQL Database:

You have successfully installed the Ubuntu 18.04.2 & Apache web server. Now it’s the time to install MySQL database on your server. Follow the below instructions to install the MySQL database. The MySQL is mainly used to store the information provided by the user on the server.

sudo apt install mysql-server

The above command will install the list of packages related to the MySQL and it will consume some space in your server. You need to enter “Y” and hit the “Enter” button.

sudo mysql_secure_installation

Now, you will be asked to configure the “VALIDATE PASSWORD PLUGIN

If you enable this feature, The MySQL will rejects the request from wrong password. So you need to be clear while entering the password and don’t forgot, save it some where else locally. Please enter the strong password.

Enter “Y” and hit the “Enter” button.

VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of the password and allows the users to set only those passwords which are secure enough.

Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No:

Now, you will be asked to enter the password level

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters, and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1

Despite whether you chose a “Validate Password Plugin“, You MySQL server will ask you about confirming the password that you entered. This is the superuser or administrative account and so you will have the increased privileges. Don’t forget to choose the Strong Password to the MySQL login.

Due to the “Validate password Plugin”, Your password strength will be shown on your screen. Now click enter button, you will be asked to “change the password”. If you are willing to change the password press “Y” and enter the new password otherwise, press “N” and click Enter button to proceed.

You will be asked more question in this setup, you can skip all the questions by entering “Y” & hit “Enter” button for each prompts.

Then finally enter the below code to exit the MySQL.

mysql> exit

Note: Don’t copy the “mysql>“. Just type “exit” & hit Enter button.

Installing PHP on the server:

PHP is playing the essential role in server side compiling the codes. This will process your codes and displays into dynamic content. This PHP has a lot of libraries and so you can able to run large number scripts, codes and more. You can easily connect the MySQL Database with PHP and so you will be able to create dynamic web apps with MySQL database.

Check this too  How to Install & Use Docker on Ubuntu 18.04 LTS Bionic Beaver

Just follow the steps to install the PHP:

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

The PHP will install in your server. But before checking it, we need to do more steps to install the PHP in your server.

Usually, Apache will look for a file “index.html”. Here we need to change the file as “index.php”, so the Apache will look for “PHP” files in your server. We are not removing the file but changing the priority of the file extension. Due to this, Apache will look for index.php initially, if the file wasn’t present the Apache will look for index.html one.

To do this, follow the below command:

sudo nano /etc/apache2/mods-enabled/dir.conf

The above code will help you to edit the Apache Directory with super user previliges.

The output will look like this:

<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.php index.xhtml index.htm

Just change the exntension from “index.html to index.php” in the first and change the “index.php to index.html” in the fourth one. After changing, it will look like the below one:

<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.xhtml index.htm

Now, Apache will look for the Index.php file. Don’t forget to save the file.

Now you should need to restart the Apache server to update the changes that you had done. Follow the below command to restart the Apache Server.

sudo systemctl restart apache2

If done anything wrong in editing the directory, the Apache will throw you the error and it will not start. You can check the status of the Apache server by entering the below command.

sudo systemctl status apache2

Now, the status of the Apache in your server will appear on your screen. We added the sample output for your clarification.

Sample Output:

● apache2.service – LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
Active: active (running) since Tue 2018-04-23 14:28:43 EDT; 45s ago
Docs: man:systemd-sysv-generator(8)
Process: 13581 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
Process: 13605 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)
Tasks: 6 (limit: 512)
CGroup: /system.slice/apache2.service
├─13623 /usr/sbin/apache2 -k start
├─13626 /usr/sbin/apache2 -k start
├─13627 /usr/sbin/apache2 -k start
├─13628 /usr/sbin/apache2 -k start
├─13629 /usr/sbin/apache2 -k start
└─13630 /usr/sbin/apache2 -k start

Enter “Q” to exit this status screen. If you get the above sample output on your screen then you have sucessfully configured the Apache server with PHP.

Now you need to install the PHP clients, “CURL” is one the best PHP client. It is mainly used to sending and receiving the request from the server.

sudo apt install php-cli

A list of packages will appear on the screen, from this you need to select the package and install it on your server.

sudo apt install package_name

That’s it, You have successfully installed the LAMP Stack on your Web server. Before making any changes, we request you to take a backup of your server. Now it is just to check the PHP on your web server.

Testing the PHP & Apache on your server:

“Php Info” is the basic method to verify the PHP & Apache functioning on the web server. Creating a simple script will show you the complete details of your servers PHP version & Apache server details.

Check this too  View Saved WiFi Passwords in Ubuntu 18.04 & Ubuntu 19.04 Linux

To create the dynamic web app files in Ubuntu 18.04.2, You just need to access the “Web Root” folder. Which is presented in “/home/s1/html/” location.

sudo nano /home/s1/html/info.php

The above code will create a new file inside the root folder and now copy the below code and paste in your server console.



After pasting the codes, save and quit.

To verify your server, you need to open the below URL in your browser.


Note: Replace “ip_address_of_your_server” with your server IP Address

Now, in the browser, you will be able to see the below images that appear on your screen.

php verify
php verify

If the above image appears on the screen, Then the PHP and Apache are successfully installed in your web server. You can start importing your dynamic web apps into the root folder through the FTP and don’t forget to delete the PHP info page.

You can delete the PHP info page by entering the below command,

sudo rm /home/s1/html/info.php

That’s it, folks, By following the above article, you will able to install the LAMP stack from the scratch on your web server.

Install LAMP on Ubuntu 18.04.2 – One-Click App Method:

Think about this, Deploying server with pre-installed LAMP stack! How cool it is, right. Digital Ocean made the whole process very easily by introducing the One Click Apps. The One Click Apps are the feature provided by the Digital Ocean, which helps you to deploy the server with Pre-installed LAMP stack.

Follow the below steps to deploy a server with Pre-installed LAMP Stack.

Create a Droplet
Create a Droplet
  • Now, go to the Marketplace Tab
  • This Marketplace tab is once called as the One-click apps
  • Here, you will able to see the list apps that are available as the pre-installed apps
Marketplace Tab
Marketplace Tab
  • Go for “LAMP” stack and scroll down
Select the LAMP Stack
Select the LAMP Stack
  • Choose the plan of your web server
  • For small dynamic websites, we suggest you go with “Standard” plans.
Droplet plan
Droplet plan
  • Select the location of your server and scroll down
Server Location
Server Location
  • Enter the name of the droplet, select the number of droplets that you want to create at this instance & finally click the Green colored button named as “Create” will deploy the server with the pre-installed LAMP stack.
Creating a Droplet
Creating a Droplet

That’s it, friends, This is the easiest way to deploy the LAMP stack server. We suggest you use the Marketplace to deploy the server. Lesser time consuming and error free.


Basically, you have installed the platform for your server. Still, you need to do more work to convert into dynamic web apps. We always suggest you create the LAMP stack through the Marketplace method than the conventional one. The Conventional one is the most precise one but a time-consuming one. The one click app method is fixed one but lesser timing. The choice is yours.

Leave a Reply

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

Written by Jim Moriarty

Hello, Am Jim from Arizona, Big Fan of Holmes. Server-side handler, Network Engineer & currently working for Tec Robust. I write a server-based article.

Contact me:
tecrobust [@]
Sub: Message to Jim.

Linux Memes, Trolls, Making Fun of “Linux” Images.

How To Install Ubuntu 18.04.2 on Digital Ocean Server Using Putty