Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Contact
  • Reviews
  • Toggle search form
Home » Linux » How to Install LAMP Stack on Ubuntu 18.04
  • WAMPServer Virtual Host
    How to create Virtual Hosts in a WAMPserver Web Server
  • screenshot 2020 03 13 at 20.24.17
    How to view installed packages in Cygwin Windows
  • Veeam Zero Trust Data Resilience
    Demystifying Zero Trust with Veeam: Design your Architecture Backup
  • enable WinRM
    WSManFault Message 2144108526 0x80338012: Fix the client cannot connect to the destination specified in the request Windows Server
  • Prevent OS Reinstallation When Switching from Legacy BIOS to UEFI
    Prevent OS Reinstallation: Change from legacy BIOS to UEFI Windows
  • PSD1 Azure 2
    How to install PSD Hydration Kit for remote bare-metal deployment or via PXE boot Windows Server
  • feature image mongo
    How to Install MongoDB on a Linux System Linux
  • azure app service with office 365 and yammer sharepoint saturday florence 2015 session 8 638
    WordPress site on Azure: How to create a website hosted in Azure Oracle/MSSQL/MySQL

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
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

  • Errno 256 No more mirrors to try 1
    How to solve Errno 256 Linux
  • parttt
    Adding a new partition to an existing Linux server Linux
  • Slide4
    How to install Let’s Encrypt on Apache Web Server Linux
  • switchlinuxusers
    How to Switch between Users in Linux Linux
  • Screenshot 2021 02 14 at 00.35.50
    How to manage automatic login on Ubuntu Linux Linux
  • 1 pUEZd8z  1p 7ICIO1NZFA
    The package python-virtualenv has no installation candidate error Linux

More Related Articles

Errno 256 No more mirrors to try 1 How to solve Errno 256 Linux
parttt Adding a new partition to an existing Linux server Linux
Slide4 How to install Let’s Encrypt on Apache Web Server Linux
switchlinuxusers How to Switch between Users in Linux Linux
Screenshot 2021 02 14 at 00.35.50 How to manage automatic login on Ubuntu Linux Linux
1 pUEZd8z  1p 7ICIO1NZFA The package python-virtualenv has no installation candidate error 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

sysadmin top30a

  • WAMPServer Virtual Host
    How to create Virtual Hosts in a WAMPserver Web Server
  • screenshot 2020 03 13 at 20.24.17
    How to view installed packages in Cygwin Windows
  • Veeam Zero Trust Data Resilience
    Demystifying Zero Trust with Veeam: Design your Architecture Backup
  • enable WinRM
    WSManFault Message 2144108526 0x80338012: Fix the client cannot connect to the destination specified in the request Windows Server
  • Prevent OS Reinstallation When Switching from Legacy BIOS to UEFI
    Prevent OS Reinstallation: Change from legacy BIOS to UEFI Windows
  • PSD1 Azure 2
    How to install PSD Hydration Kit for remote bare-metal deployment or via PXE boot Windows Server
  • feature image mongo
    How to Install MongoDB on a Linux System Linux
  • azure app service with office 365 and yammer sharepoint saturday florence 2015 session 8 638
    WordPress site on Azure: How to create a website hosted in Azure Oracle/MSSQL/MySQL

Subscribe to Blog via Email

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

Join 1,825 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

AWS 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.