Ubuntu

How to Install and Configure LAMP Stack?

How to Install and Configure LAMP Stack

For Web Application Development we mostly use or prefer either the MERN stack or the MEAN stack. LAMP Stack is also used for Web Application Development. It consists of Four Components that the term “LAMP” is derived from:

  1. Linux Operating System, which works as a server operating system.
  2. Apache HTTP Web Server.
  3. MySQL, which is used for Database Management.
  4. PHP programming language.

This article showcases the installation and configuration of LAMP Stack in Linux Distribution, mainly Ubuntu.

How to Install and Configure LAMP Stack on Ubuntu 22.04?

The steps below will guide you through the complete process of installing and configuring the LAMP Stack in Ubuntu, which is among the popular Linux Distribution Systems.

Step 1: Installing Apache Server

Before installing the Apache HTTP Server, ensure the package list is up to date by using the command:

sudo apt update

“sudo” gives the user admin privileges.

Run the command below to install Apache Packages:

sudo apt install apache2

During installation, it will ask for confirmation, press “Y” to continue the process:

To check the status of the installed Apache Server, run the command:

sudo service apache2 status

If it is installed, it will highlight the server as “running” in the command prompt:

Now, check if your UFW Firewall contains the Apache profile. The UFW(Uncomplicated Firewall) provides a simple way to configure your firewall. Run the command below to check your Apache profile in UFW:

sudo ufw app list

Here we have the Apache Full Profile. Ensure that the Apache Full allows traffic on ports 80 and 443. Port 80 allows the information to be in plain text between the browser and server, whereas Port 443 allows the information to remain encrypted between the browser and server. Check Ports by running the command:

sudo ufw app info "Apache Full"

Now to check whether your Apache Server is running, run any internet browser in Ubuntu, and in the address bar type “localhost”. It will navigate you to the Apache Web Page:

If the default Apache Web Page displays, it means that the server is up and running.

Step 2: Installing MySQL

For the Database Management System in LAMP Stack, MySQL is used. To install MySQL in Ubuntu, execute the command:

sudo apt install mysql-server

When installed you can see the terminal ensuring the “sql-server” is running

You can also verify the SQL Server installation using the command

mysql -V

This will show the “sql-server” version

Step 3: Installing PHP

As PHP integrates well with MySQL, it is preferred over Python and Pearl for Web Development Projects. Although Python and Pearl can also be used, but the speed and complexity of Web Application usually improves when PHP is embedded into HTML.

To install PHP, obtain the packages first by using the command:

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

During installation, it will ask for confirmation, press “Y” to continue the process. Once the necessary packages are obtained, modify the Apache Server Files using the command:

sudo nano /etc/apache2/mods-enabled/dir.conf

By default, the Apache server looks for the “index.html” file. Change the “index.html” file with “index.php” by editing the file:

Save the file and then exit using “Ctrl+X”.

Step 4: Rebooting Apache

Using the following command, reboot the Apache server for the changes to take effect:

sudo systemctl restart apache2

If the server restarts, the command line will move to the next line:

Step 5: Testing

Create a file in the root directory with a basic PHP Script to check if the LAMP installation is working or not on your local host. Using the command below, create a file in the root directory:

sudo nano /var/www/html/info.php

Once executed, the file will open:

Add the PHP script below:

<?php
phpinfo ();
?>

Save the file and then exit by pressing the “Ctrl+X” keys:

Fire up your internet browser on Ubuntu and in the address bar, type the following address:

localhost/info.php

This address will open the PHP Details:

That’s all about installing and configuring the LAMP Stack on Ubuntu 22.04.

Conclusion

Install and Configure LAMP Stack in Ubuntu by installing Apache Server, setting up MySQL, integrating PHP, and then testing LAMP on localhost. LAMP is a common open-source software stack that developers use to build interactive web pages and web applications. Depending on the scope of our web application, LAMP is typically fast and reliable compared to other stacks like MERN and MEAN. In this article, we explored what the LAMP stack is, dealt with the installation process, and analyzed the configuration of the LAMP Stack in Ubuntu.

Similar Posts