Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security, Veeam & DevOps

  • Home
  • About
  • Advertise With US
  • Contact
  • Reviews
  • Toggle search form

How to Install LAMP Stack on Ubuntu 18.04

Posted on 22/12/202128/09/2023 Raphael Gab-Momoh By Raphael Gab-Momoh No Comments on How to Install LAMP Stack on Ubuntu 18.04
  1. Home
  2. Linux
  3. How to Install LAMP Stack on Ubuntu 18.04
lampstack-feature-lamp-stack-ubuntu

The LAMP stack is a collection of open-source tools for developing web applications. In addition, an operating system, a web server, a database, and a programming language are all required for a web application to function. For a database-driven and dynamic website, each layer of software is critical. So, here’s a step-by-step tutorial on how to install LAMP Stack on Ubuntu 18.04. In this guide, I will walk you through how to install each of the components as it is important that we install each component of the stack separately. You can view similar guides from here: How to Configure Advanced PAM in Linux/ and How to locate directory file context and restore it with SELinux/ also differences between dnf and apt package managers/ and How to create and deliver a report on System Utilization on a Linux based OS

The acronym LAMP stands for the following programs:

Linux which is a free and open-source operating system.
Apache which is an HTTP Server 
MySQL which is a relational database management system.
PHP which is a scripting language. Please also take a look at this guide: How to setup and configure a lamp stack on CentOS.

Requirements for installing LAMP Stack on Ubuntu 18.04

Ubuntu user with sudo rights in Ubuntu 18.04 Bionic Beaver
The ability to use a terminal/command line
The apt package manager, which comes pre-installed in Ubuntu and other Debian-based distributions.

Steps to Install LAMP Stack on Ubuntu 18.04

Step 1: Update Package Repository Cache

Update the package repository cache to guarantee that the software is installed with the most recent versions. Therefore, to successfully install LAMP Stack on Ubuntu, you need to update package repository to the latest version. To do so, enter the command below.

sudo apt update

Step 2: Install Apache Server on Ubuntu 18.04

Run the following command in the terminal to install Apache:

sudo apt install apache2

Hit y which means yes & enter on your keyboard when prompted

apache-2
apache 2

It is alright but just to be sure we will run another command to check the status

sudo service apache2 status
status

Next, type the following command to see if the UFW firewall has an application profile for Apache:

sudo ufw app info "Apache Full"
ports
ports

To know how if installation works, we need to run the local IP address and specify the port highlighted above. Hence, we can get the IP by running the command.

curl http://icanhazip.com
ipaddress
how to get ip
apache2
apache 2

Step 3: Install MySQL and Create a Database

sudo apt install MySQL-server

To check if our MySQL-server has been installed, run the following commands below

#systemctl start MySQL. Service
#systemctl status MySQL. Service
mysql
MySQL running

Step 4: Install PHP

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

The next step to install LAMP Stack on Ubuntu 18.04 is to change how Apache serves files when directories are needed. Thus, Apache scans for a file card named index.html by default. Rather than searching for the index.html file, we want it to look for the index.php file.

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

The command we ran gave us the output above, we need to swap the position of index.html and index.php so that index.php is number 2. After the swap we save and close the file.

how to install LAMP Stack on Ubuntu 18.04- index.php_
dir.conf

Press CTRL + X to save and close the file. Then, press y and ENTER to confirm.

Step 5: Restart Apache

We need to restart the Apache service for the modifications to take effect.

sudo systemctl restart apache2

Step 6: Test PHP Processing on Web Server

To confirm that you’ve installed LAMP Stack on Ubuntu 18.04, create a simple PHP script and save it in the “web root” folder. Meanwhile, this is required for Apache to correctly locate and serve the file. /var/www/html/ is the location of this directory.

Type the following command to generate a file in that directory:

sudo nano /var/www/html/info.php

This opens an empty nano file

how to install LAMP Stack on Ubuntu 18.04-empty-nano-file
empty nano file

To install LAMP Stack on Ubuntu 18.04, we need to type in the PHP code below:

<?php
phpinfo ();
?>

Then, press CTRL + X to save and close the file. Press y and ENTER to confirm.

To confirm that our LAMP stack on Ubuntu 18.04 is installed and working, Open a browser and type in your IP address/info.php

NOTE: only the IP address of the VM will make this work so run ip addr show in terminal and copy the ip.

 how to install LAMP Stack on Ubuntu 18.04-info.php_
php

Summary

Congratulations, we have successfully installed the LAMP stack on Ubuntu 18.04. This we did by installing each of the components individually and this is especially important for web development.

Rate this post

Thank you for reading this post. Kindly share it with others.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
  • Share on Threads (Opens in new window) Threads
  • Share on Nextdoor (Opens in new window) Nextdoor
Linux Tags:MySQL, MySQL-server

Post navigation

Previous Post: How to Configure Advanced PAM in Linux
Next Post: Setup Public Load Balancer in Azure

Related Posts

  • MV command in Linux
    Rename or Move Files or Directories in Linux with Bash Terminal Linux
  • Screenshot 2020 05 14 at 17.47.09
    SSH access on Ubuntu server: Easy Guide Linux
  • images copy
    How to clean packages lying around in Linux Linux
  • goland
    How to install Golang on a Linux System Linux
  • Featured image WSL2 installation
    How to install WSL2 on Windows Server Linux
  • HAProxy
    Deploying a load balancer from scratch and adding backend servers Linux

More Related Articles

MV command in Linux Rename or Move Files or Directories in Linux with Bash Terminal Linux
Screenshot 2020 05 14 at 17.47.09 SSH access on Ubuntu server: Easy Guide Linux
images copy How to clean packages lying around in Linux Linux
goland How to install Golang on a Linux System Linux
Featured image WSL2 installation How to install WSL2 on Windows Server Linux
HAProxy Deploying a load balancer from scratch and adding backend servers Linux

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

Veeam Vanguard

  • Creating a WinPE USB Drive Fixing System Boot Issues
    Creating a WinPE USB Drive: Fixing System Boot Issues Windows
  • PXE Boot Stuck or No Boot Image was found   Te bootloader did not find any operating system
    Fix PXE Boot Stuck or No Boot Image was found for HyperV VM Virtualization
  • azure just in time
    How to secure access to your Virtual Machine with Just-in-Time (JIT) VM Access AWS/Azure/OpenShift
  • encrypt your Data with Trellix Data Encryption
    How to encrypt your system with Trellix Data Encryption Security | Vulnerability Scans and Assessment
  • Security enhanced linux
    How to setup SELinux on a Linux server Linux
  • SysInternals
    Use Active Directory Explorer from Sysinternals Windows
  • Veeam Ready Tape
    Enterprise Tape Library Administration: Control Path, Firmware, Media Management and Tape Operations Backup
  • featured 2 2
    Clone a repository and install software from GitHub on Windows Windows Server

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,796 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

Active Directory Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2025 TechDirectArchive

Loading Comments...

You must be logged in to post a comment.