How To Install LAMP In Ubuntu 18.04/20.04

How To Install LAMP In Ubuntu 18.04. In this tutorial, We’ll show you how to install Lamp on Ubuntu 18.04 server. The LAMP is stands for Linux, Apache, Mysql, and PHP. It is an open source platform and works on the Linux operating system. It uses Apache web server, MySQL relational database management system, and PHP object-oriented scripting language.

Before we install Lamp in ubuntu 18.04. We will know about Lamp.

L => Linux operating system
A => Apache web server
M => MySQL relational database management system
P => PHP object-oriented scripting language

Before Install the Lamp on Ubuntu. First update the apt package :

sudo apt-get update

sudo apt-get upgrade

How To Install LAMP In Ubuntu 18.04

  • 1. Install The Apache On Ubuntu
  • 2. Install MySQL on Ubuntu
  • 3. Install PHP 7.2 On Ubuntu
  • 4. Test PHP Version

1. Install The Apache On Ubuntu

Install apache on ubuntu using this below command :

sudo apt-get install apache2

Check Apache Status :

After the Apache installation process, the web server service should be started automatically, You can check the Apache service status :

sudo systemctl status apache2

apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
   Active: active (running) since Sun 2018-12-31 05:18:45 PDT; 2min 30s ago
 Main PID: 3143 (apache2)
    Tasks: 55 (limit: 2321)
   CGroup: /system.slice/apache2.service
           |-3143 /usr/sbin/apache2 -k start
           |-3144 /usr/sbin/apache2 -k start
           `-3145 /usr/sbin/apache2 -k start

Manage the Apache services using these below commands :

To start Apache

sudo systemctl start apache2

To Stop Apache

 sudo systemctl stop apache2 

Restart Apache

sudo systemctl restart apache2

Disable Apache

sudo systemctl disable apache2

2. Install MySQL on Ubuntu

Execute the following command to install MySQL server into your ubuntu server:

sudo apt install mysql-server

Secure MySQL Server Installation

Default MySQL is insecure , we need to secure the database server.

After installation is complete, the mysql_secure_installation utility runs. 
Run the below command and answer the few questions based on your environment requirements.

sudo mysql_secure_installation

3. Install PHP 7.2 On Ubuntu

Execute the following command to install PHP 7.2 version on ubuntu server:

sudo apt-get install python-software-properties -y 

sudo add-apt-repository ppa:ondrej/php

Install PHP with Exetension

sudo apt-get install php7.2

sudo apt-get install php7.2-<extension-name>

See example below

sudo apt-get install php7.2-fpm  php7.2-curl php7.2-mysql \  php7.2-xml php7.2-zip php7.2-gd

4. Test PHP Version

Test your server by executing the following command:

Use the below command to check the PHP version installed on your server :

php -v

Finally, we need to restart the Apache Web Server :

sudo systemctl restart apache2


In this article, we have successfully installed LAMP on Ubuntu 18.04.

If you have any questions or thoughts to share, use the comment form below to reach us.


My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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