Dion
4 min readOct 22, 2023

How To Install a LAMP Stack Server using Ubuntu 22.04

For a Server to effectively host website and web Apps written in PHP, it needs a group of Open Source Software known as a LAMP Stack. They are installed together

The word LAMP is an acronym for Linux, Apache, MySQL and PHP.

Linux: This is the most popular and secure Open Source operating System used in web servers.

Apache HTTP Server: This is a free, open source web server that delivers web content through the internet.

MySQL: A relational Database engine that allows you to store data and manage it.

PHP: Open Source and general purpose server side scripting language used mainly in web development to create dynamic website and apps.

Step 1: Update the Ubuntu Environment.

This is done with a simple line of sudo command.

# sudo apt update

Step2: Install and Setup Apache HTTP Server on Ubuntu 22.04

# sudo apt install apache2 libapache2-mod-php8.1 -y

To verify configuration;

# sudo systemctl status apache2

The diagram shows that apache is active and running.

After this is done, the firewall needs to be adjusted to allow either HTTP, HTTPs or both on their various ports. The firewall comes already installed in Ubuntu. This is known as Uncomplicated Firewall.

The application profiles are:

Apache: Only opens port 80

Apache full: opens both port 80 and port 443.

Apache secure: Only opens port 443. (TLS/SSL encrypted traffic).

For HTTP traffic;

# sudo ufw allow “Apache”

Reload the firewall to effect the change:

# sudo ufw reload

To verify the status of the firewall

# sudo ufw status

The diagram shows that only the Apache profile is active.

We can verify the accessibility of the web server from a web browser by browsing the ip address of the server.

# http:://[server’s IP address]

The server would display the welcome page for ubuntu/Apache2. This page should carry, It works as proof that it is active.

To get the Server’s IP address,

# hostname -i

Step 3: Installing PHP and PHP Extensions:

PHP is already in the Ubuntu workspace.

The PHP module, php-mysql: enables interaction between the PHP and MySQL-based database.

Libapache2-mod-php: enables apache to handle PHP files.

Php-xml: This package that provides a DOM, SimpleXML, WDDX, XML, and XSL module for PHP.

#sudo apt install php libapache2-mod-php php-mysql php-xml

To verify the version of PHP:

#php -v

Step 4: Installing Database Server.

Database server is used to store and manage data for the sites. MySql can be used as the database server, but MariaDB will be used in this scenario. This is due to its functionality, high performance and the vast features it possesses.

To install MariaDB;

# sudo apt install mariadb-server -y

To Verify;

# sudo systemctl status mariadb

Once installation is complete, we can enable it using;

# sudo systemctl enable mariadb

Most database installation files comes with weak security and could experience intrusions and breaches. However, it is recommended that security measures should be taken by running the security script that comes with the database.

# sudo mysql_secure_installations

This will prompt to configure the VALIDATE PASSWORD PLUGIN.

ANSWER Y and it will prompt to select a level of password validation.

Enter 2, this is the medium level of security, set up and confirm.

Enter y for the remaining prompts to give the database the best security standard.

Log in to the console using:

# sudo mariadb

To test the PHP integration on Apache web server;

Create a php file in the document root directory

# sudo nano /var/www/html/Dion.php

We can proceed to restart the Apache to apply the changes.

# sudo systemctl restart apache2

On the web browser, we can search for;

# http://[server-ip]/Dion.php

The diagram above shows that we have successfully setup LAMP Stack on Ubuntu.