Share your love
Complete LAMP Stack Installation on Ubuntu 24.04 for Beginners
This guide will teach you a Complete LAMP Stack Installation on Ubuntu 24.04 for Beginners. LAMP Stack is a popular and open-source tool that is used in web development. It stands for Linux, Apache, MySQL/MariaDB, and PHP. Each of these services is an essential layer of the stack. They are used to create database-driven, dynamic websites.
Now you can follow the guide steps that are provided by the Orcacore website and start your LAMP Stack Installation on Ubuntu 24.04.
Table of Contents
Steps To LAMP Stack Installation on Ubuntu 24.04
Before you start your LAMP Stack installation on Ubuntu 24.04, you must access your server as a non-root user with sudo privileges. To learn how you can create a sudo user, you can check this guide on Create a Sudo User on Ubuntu 24.04 From Terminal.
Then, follow the steps below to start your LAMP Stack installation on Ubuntu 24.04.
Step 1 – Installing Apache Web Server on Ubuntu 24.04
The first step is to install Apache on Ubuntu 24.04 as the web server. To do this, run the system update and install Apache with the command below:
# sudo apt update
# sudo apt install apache2 -y
Allow HTTP Traffic To UFW Firewall
Once your Apache installation is completed, you must allow the HTTP traffic through the UFW firewall. To install and enable the UFW Firewall, you can check this guide on UFW Firewall Configuration on Ubuntu 24.04.
First, you can list all currently available UFW application profiles with the command below:
sudo ufw app list
In your output, you should see something similar to this:
Output
Available applications:
Apache
Apache Full
Apache Secure
OpenSSH
At this point, you only need to allow port 80. To do this, you can run the command below:
sudo ufw allow in "Apache"
Now you can verify your Apache installation and UFW configuration by accessing the default Apache web page. To do this, you need to know your server’s IP address. For this purpose, you can check this guide on 4 Linux Commands to Get Public IP Address.
Then, open your favorite web browser and navigate to the following URL:
http://your_server_ip
If you see the following page means you have correctly installed Apache on Ubuntu 24.04.
Step 2 – Installing MariaDB on Ubuntu 24.04
At this step of LAMP Stack installation on Ubuntu 24.04, we install MariaDB as the database engine. To install MariaDB, you can simply run the command below:
sudo apt install mariadb-server -y
Run MariaDB Security Script
When the installation is finished, it is recommended to run a security script that comes pre-installed with MySQL. To do this, run the command below:
sudo mysql_secure_installation
You will be asked to:
- Setting a strong root password
- Removing anonymous users
- Disabling remote login for the root user.
- Removing the test database and access to it.
Answer them to continue.
When you’re finished, test whether you’re able to log in to the MariaDB console by typing:
sudo mysql -u root -p
Then, you can exit from your MariaDB shell with the command below:
MariaDB [(none)]> exit
Step 3 – Installing PHP on Ubuntu 24.04
The final step of LAMP Stack installation on Ubuntu 24.04 is installing PHP. Also, you need php-mysql, a PHP module that allows PHP to communicate with MySQL-based databases. You also need libapache2-mod-php to enable Apache to handle PHP files. Core PHP packages will automatically be installed as dependencies.
To install the PHP and required packages, run the following command:
sudo apt install php libapache2-mod-php php-mysql -y
Verify PHP Installation
Once your installation is completed, you can verify it by checking the PHP version:
php -v
In your output, you should see:
As you saw, the default PHP version in Ubuntu 24.04 is PHP 8.3.
Next, you can create a PHP test script to confirm that Apache can handle and process requests for PHP files. To do this, you can run the command below:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Then, type your server’s IP address in your web browser followed by info.php:
http://server-ip-address/info.php
Here is an example of the default PHP web page:
After checking the relevant information about your PHP server through that page, it’s best to remove the file you created as it contains sensitive information about your PHP environment and your Ubuntu server:
sudo rm /var/www/html/info.php
You can always recreate this page if you need to access the information again later.
That’s it, you are done.
Conclusion
At this point, you have learned LAMP Stack installation on Ubuntu 24.04 which includes Apache, MariaDB, and PHP. You can use them together for creating database-driven and dynamic websites. Hope you enjoy it. Also, you may like to read the following articles:
Apache2 service failed with result exit code