How to Install LAMP Stack on Ubuntu 24.04
LAMP Stack is an open-source, powerful set of tools used to create and host web applications. In LAMP Stack, L is the abbreviation for Linux, A for Apache, M for MySQL, and P for PHP programming. It is a popular choice for system users or developers who have the passion and craze to develop web applications regularly. All the components in the LAMP Stack are free, efficient, and have large community support, thus, you won’t feel any difficulty handling them.
For Ubuntu 24.04, which is a Linux system, the LAMP Stack integrates seamlessly and provides you with a stable and reliable platform for web development.
Read this guide to find:
How to Install LAMP Stack on Ubuntu 24.04
The LAMP Stack is a combination of different tools like the Linux Operating System, Apache Server, MySQL (MariaDB) Database Server (MySQL), and PHP. Since we have already installed Ubuntu 24.04, which is a Linux operating system, we don’t require another operating system. However, you must install other tools like Apache Server, MariaDB Database, and PHP on your Ubuntu system to complete the LAMP Stack installation.
Follow the below-given steps to install these tools.
Step 1: Update Ubuntu Repository
You can find and install the tools used in the LAMP Stack installation directly from the Ubuntu standard repository. However, before that, you should update the Ubuntu repository first using the following command to ensure the up-to-date installation of packages:
sudo apt update && sudo apt upgrade -y
Step 2: Install Apache Server on Ubuntu 24.04
The first tool required for LAMP Stack installation on Ubuntu 24.04 is the Apache Web Server, which you can install from the following command:
sudo apt install apache2 -y
After completing the Apache installation, run the below-given command to ensure it is active and running on the system:
sudo systemctl status apache2
Step 3: Install Firewall on Ubuntu 24.04
Next, you should also install Uncomplicated Firewall (UFW) on Ubuntu using the following command:
sudo apt install ufw
The UFW will help you in routing the HTTP traffic on the default Port 80. After you complete the UFW installation on Ubuntu, run the following command to enable it on the system:
sudo ufw enable
Then allow the HTTP traffic on Port 80 by using the below-given command:
sudo ufw allow 80/tcp
Once done, reload the UFW on Ubuntu through the following command:
sudo ufw reload
Step 4: Open Apache2 Default Page
To ensure the installation of Apache is successful, you can open the Apache2 default page on your browser by using the IP address of your Ubuntu server. You can find the IP address of your Ubuntu system directly from the terminal using the following command:
hostname -I
Once you find your Ubuntu server IP address, open a browser on your other computer and enter the IP address of your Ubuntu system. It will open the Apache2 default page on the browser that ensures that Apache is successfully running on your system.
Step 4: Install MySQL (MariaDB) Database Server on Ubuntu 24.04
Now for LAMP Stack installation on Ubuntu, you will also require MySQL database server installation. MySQL installation will help you in storing the site data so that you can retrieve and manipulate the data through PHP. However, instead of installing MySQL, here we are installing the MariaDB server, which is a drop-in replacement for the MySQL server. It provides better efficiency and speed in terms of handling complex tasks.
You can install the MariaDB server and client on the Ubuntu system through the following command:
sudo apt install mariadb-server mariadb-client -y
You can confirm the MariaDB server installation on Ubuntu using the below-given command:
mariadb --version
Step 5: Secure MySQL Database Server
The default configuration for MySQL server is weak and may pose a potential risk to your database. However, you can secure the MySQL installation on Ubuntu by running the following command:
sudo mysql_secure_installation
After the command execution, the script will run, providing you with different options to choose from. The first option will be entering the current password for root. Since, by default, no root password is set, you can move forward by simply pressing the Enter button. After that, use the n option when it asks you to switch unix socket authentication:
Then follow the on-screen instructions for choosing other options in the script:
Keep with the same onscreen instructions and once all things are done, you will be greeted with the message that your MariaDB server is secure now:
Step 6: Install PHP on Ubuntu
The final tool you should install for completing the LAMP Stack installation on Ubuntu is PHP. PHP is a versatile language that integrates well with the MySQL server and is used for developing web applications.
You can install PHP on the Ubuntu directory from the apt repository using the following command:
sudo apt install php -y
To confirm the PHP installation on Ubuntu, use the below-given command:
php --version
Besides that, you can also install PHP modules to enhance the functionality of PHP. You can search for several PHP modules and libraries from the apt repository using the following command:.
apt-cache search php- | less
After that, pick modules from the list and install them on your system from the apt install command, followed by the module and library name. Here, as an example, we have installed php8.3-sqlite3 package on Ubuntu from the following command:
sudo apt install php8.3-sqlite3 -y
At this stage, we have completed the LAMP Stack installation on Ubuntu 24.04.
Step 7: Test LAMP Stack Installation on Browser
In this final step, you can test the LAMP Stack installation by creating a web server through PHP. For that purpose, first, run the below-given command to restart your Apache server on Ubuntu so that changes should be loaded correctly.
sudo systemctl restart apache2
Then create a PHP script file in the Apache web root directory using the following command:
sudo nano /var/www/html/file_name.php
Ensure changing the file_name according to your choice. Once the file is opened, you can add the PHP code inside the file; as an example, I am adding the following code inside the PHP file:
<?php echo "Welcome to LinuxGenie Website" ?>
Save the PHP file using CTRL+X, add Y and press Enter to exit. Then navigate to the web browser and enter your server IP address with the PHP file name:
http://server-ip-address/linuxgenie.php
This will open the output of the PHP file on the browser:
The output on the browser indicates that the LAMP Stack web server is successfully created and running on your system.
Conclusion
LAMP Stack is a robust set of tools used for creating and hosting web applications. This article has covered the installation of LAMP Stack on Ubuntu 24.04. Here, we have learned methods to install Apache, Firewall, MySQL (MariaDB) database, and PHP on the Ubuntu system. All the tools used for LAMP Stack installation can be installed directly from the Ubuntu standard repository. Apart from that, we have also set up a LAMP Stack web server to ensure all the tools are installed and running seamlessly on your system.




















