Install LAMP Stack on Ubuntu 22.04: A Comprehensive Guide

The LAMP stack, also referred to as a LAMP server, is a comprehensive software bundle that simplifies the process of developing dynamic web applications. This guide will walk you through the installation of the LAMP stack on an Ubuntu 22.04 system.

Typically, the LAMP stack incorporates MySQL for database management. However, in this tutorial, we will use MariaDB instead of MySQL. MariaDB is often preferred in various Linux environments for its enhanced performance characteristics.

In this detailed tutorial, you’ll learn how to set up LAMP on Ubuntu 22.04 with MariaDB as your database management system.

Introduction

LAMP stands for Linux, Apache, MySQL, and PHP – four critical elements that combine to create a LAMP server or LAMP stack. This configuration is renowned for its stability and high efficiency, offering an ideal platform for hosting and running web applications.

Step 1: Preparing Your Ubuntu System

$ sudo apt update
$ sudo apt upgrade

Step 2: Install Apache

$ sudo apt install apache2

Upon installation, The Apache web servers starts automatically. You can verify this by checking the status as shown.

$ sudo systemctl status apache2

From the output, we can see that the webserver is up and running.

Next, enable Apache to run automatically on system boot as shown:

$ sudo systemctl enable --now apache2

If you are running behind a firewall allow the webserver service using the following command:

$ sudo ufw allow 'Apache'

To verify that apache is correctly installed, head over to your server’s ip address.

http://server-ip-address

The default Apache web page should be displayed on your browser.

Step 3: Install MariaDB database server

MariaDB is hosted on Ubuntu repositories by default, and you can install it right away as follows.

$ sudo apt install mariadb-server

Like Apache, MariaDB also starts automatically once the installation is done. To confirm that MariaDB is running check the status of MariaDB on the system:

$ sudo systemctl status  mariadb

Additionally, it’s important to ensure that the database service is configured to start automatically upon system boot. This step ensures that your database is always available and ready for your applications immediately after the system starts, enhancing reliability and uptime for your web applications.

$ sudo systemctl enable mariadb

To improve the security of MariaDB, run the security script, which is included as part of MariaDB installation.

$ sudo mysql_secure_installation

Next, be sure to provide a strong database root password and confirm it.

To secure your database server,  type ‘Y‘  for the remaining prompts to achieve the following:

  1. Remove anonymous users
  2. Disallow remote root login
  3. Remove test database
  4. Reload privilege tables

Step 4: Install PHP and the Required Extensions

$ sudo apt install php8.1 libapache2-mod-php8.1

To view the version of PHP installed, run the command:

$ php -v

Install some PHP extensions.

$ sudo apt install  php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-intl -y

Create a PHP script to test out PHP integration with Apache.Run the following command:

$ echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Visit the server URL

http://server-ip/info.php

Conclusion

The LAMP stack is a favored choice for developers when it comes to constructing full-stack web applications. This guide has provided comprehensive instructions on how to successfully install the LAMP stack on Ubuntu 22.04.From here, you can proceed and host your website(s) on the LAMP stack.

One thought on “Install LAMP Stack on Ubuntu 22.04: A Comprehensive Guide

Leave a Reply

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