A Step-by-Step Guide to Installing Apache, MySQL, PHP (LAMP stack) on Ubuntu 22.04


Setting up a LAMP stack on Ubuntu 22.04 is a great way to quickly and easily get your web server environment up and running. In this step-by-step guide, we’ll walk you through the process of installing Apache, MySQL, and PHP (LAMP stack) on Ubuntu 22.04. We will also provide some helpful tips for troubleshooting any issues that may arise during the installation process. By following this guide, you will be able to create a powerful web server that is capable of hosting dynamic websites and applications.

What is a LAMP Stack and What Are the Benefits of Installing It?

A LAMP stack is a combination of open source software, running on a Linux operating system, that is used to create dynamic web applications. It stands for Linux, Apache, MySQL and PHP. The LAMP stack provides an efficient way to develop and deploy web applications with the help of its various components. It offers cost-efficiency, scalability and flexibility along with improved performance when compared to traditional web hosting solutions. Additionally, it is easy to install and maintain due to its open source nature. Installing the LAMP stack can provide many benefits such as increased security, faster development time and better performance for your web applications.


Below is a list of items that may be needed to complete this tutorial successfully:
1) A desktop or laptop with at least 4GB of RAM, a dual-core processor, and at least 50GB of free disk space
2) The Linux Ubuntu 22.04 LTS disk image file
3) A cloud VPS or self-hosted virtual machine where you can install Ubuntu Server
4) Installation packages for Apache, MariaDB, and PHP
5) An SSH client such as Putty or the built-in terminal app on a macOS device


The list below outlines the steps covered in this tutorial:
1) Download Linux Ubuntu server 22.04 LTS and create a virtual machine
2) Connect to the virtual machine via SSH and install updates
3) Install the LAMP stack and test the set up
4) Create a virtual host and configure a Let’s Encrypt SSL certificate.
5) Frequently asked questions & troubleshooting

1. Download Linux Ubuntu Server 22.04 LTS and create a virtual machine

Start the setup by downloading the Linux Ubuntu Server disk image file from the official download page. If you already have an Ubuntu Server set up, you can skip this step.  Go to and click Download > Get Ubuntu Server. Click Download Ubuntu Server 22.04 LTS to get the iso image file for the operating system. 

When the download is complete, use VirtualBox, VMware Workstation, or VMware fusion to create a new Linux Ubuntu virtual machine. Click HERE for further details on how to do this.

2. Connect to the virtual machine via SSH and install updates

Proceed to connect to the virtual machine via SSH. If you are using a macOS device, open the terminal app and run the command below to connect. 

If you are using a Windows based device, download and install the Putty SSH client. Open Putty and enter the IP address of the Ubuntu virtual machine on the Host (or IP address ) field, ensure the port is set to 22 and click the Open button. Enter the server password to gain access.

Now that you have connected to the Ubuntu Server via SSH, run the commands below to update the system repository and upgrade system packages

Restart the server for the changes to take effect.

3. Install the LAMP stack and test the setup

The makers of Linux Ubuntu have made it simple to set up the LAMP stack on both server and desktop versions of the operating system. In this guide, we’ll use the apt package manager to set up the LAMP stack. Rn the command below to install the Apache web server:

When the installation completes, run the commands below to allow the Apache service to start automatically at system start up:

If your server uses the uncomplicated firewall as it defence mechanism, configure ufw to permit connections on TCP port 80 and TCP port 443. These are the network ports that Apache uses to serve web pages.
You can also execute the command below to verify that UFW will not block Apache connections
It is important to test the Apache web server after installing it. By default Apache ships with a test page that can be used to verify if the web server is working okay. Open a new browser window and go to http://your-server-ip or http://your-server-domain-name. The Apache default welcome page will be displayed.

Install the MariaDB database server

The next component of the LAMP stack that needs to be installed is the MariaDB database server. MariaDB is an open-source relational database management system (RDBMS) that is used to store and manage data. It is based on MySQL, a popular database system, and provides many of the same features. MariaDB has become a popular choice for businesses due to its scalability, performance, and reliability. It also offers a wide range of features such as high availability, replication, query optimization, and more. Execute the command below to install the MariaDB database server and client.

Start MariaDB and set it to launch at system start up

5. Frequently asked questions & troubleshooting

What is the main advantage of LAMP is in Linux?

The main advantage of using LAMP in Linux is that it allows developers to quickly and efficiently create powerful web applications with minimal effort. With the combination of these four components, developers can easily create robust websites with the help of the integrated scripting language like PHP or Perl. Additionally, they can use the database management system like MySQL to store data securely and access it quickly when needed. This makes it an ideal solution for businesses looking to build dynamic web applications without having to invest in expensive hardware or software solutions.

What can I use instead of LAMP in Linux?

For those looking for an alternative to the popular LAMP stack, there are a variety of options available. From lightweight web servers like Nginx and Lighttpd to open source databases like MongoDB and MariaDB, Linux users have plenty of choices when it comes to building their own custom stack. Each option offers its own unique advantages and disadvantages, so it’s important to do some research before making a decision. With the right combination of tools, you can create a powerful and efficient system that will meet all your needs.