Open In App

How to Set Up a LAMP Stack in Linux?

Last Updated : 28 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

LAMP stands for Linux, Apache, MySQL, and PHP, which are all open-source software components. Together they create a foundation for running dynamic websites and web applications. LAMP is a popular choice for users or developers due to its affordability, flexibility, and wide range of supported application systems.

In this article, we will set up LAMP Stack on various Linux distributions like Ubuntu, Fedora, Red Hat Enterprise Linux (RHEL), etc.

How to Install LAMP Stack in Linux?

We must install Apache web server, MySQL, and PHP to set up a LAMP Stack in Linux. Here we’ll see all the step-by-step process for better understanding.

Prerequisites

Step 1: Checking Linux Distribution

Make sure you have Linux all set and running. To check which Linux distribution you have installed use the following command:

command : grep -E '^(VERSION|NAME)=' /etc/os-release
checking-installed-linux-distro

checking installed Linux distribution

And follow the steps according to your installed Linux distribution.

Step 2: Upgrading Linux distribution to the latest packages.

On Ubuntu/Debian-based systems

We use the apt package manager to update and upgrade Ubuntu/Debian-based systems.

apt update will update all the packages to the latest versions and apt upgrade will download and install the required packages.

command : sudo apt update && sudo apt upgrade

On Fedora-basedfedora-based systems

In the fedora-based Linux distribution, we use dnf package manager.
dnf RHEL-based update which makingRHEL-basedupdate command will update repositories and download and install necessary updates.

command : sudo dnf update -y

On RHEL-based systems

On Red Hat Enterprise Linux distributions we use the yum package manager.

Similar to the DNF, package manager, the yum update command will update repositories and download and install necessary updates.

command : sudo yum update -y
upgrading-system

Upgrading System

1. Installing Apache Web Server

Step 1: Install Apache Web Server using the package manager

On Ubuntu/Debian-basedFedora-based systems

command : sudo apt install apache2 -y

On Fedora-basedRHEL-based systems

command : sudo dnf install httpd -y

On RHEL-based systems

command : sudo yum install httpd -y
installing-apache-web-server

Installing Apache Web Service

Step 2: Enable services

We will use the systemctl command to manage all Apache servers’ or Debian-based services.

On Ubuntu/Debian-basedFedora-based systems

command : sudo systemctl enable apache2

On Fedora-basedRHEL-based systems

command : sudo systemctl enable httpd.service

On RHEL-based systems

command : sudo systemctl enable httpd.service
enabling-services-for-apache

starting services for the Apache Web Server

Step 3: Verify Apache Web Server Installation

To verify Apache Web Server installation, use the -v command.

On Ubuntu/Debian-basedFedora-based systems

command : apache2 -v

On Fedora-basedRHEL-based systems

command : httpd -v

On RHEL-based systems

command : httpd -v
verifying-apache

Verifying Apache web server installation

2. Installing MySQL (MariaDB)

Step 1: Install MariaDB using the package manager

On Ubuntu/Debian-basedFedora-based systems

command : sudo apt install mariadb-server mariadb-client

On Fedora-basedRHEL-based systems

command : sudo dnf install mariadb mariadb-server -y

On RHEL-based systems

command : sudo yum install mariadb mariadb-server -y
installing-mariadb-mysql

installing MySQL (MariaDB)

Step 2: Starting Services for MariaDB

Start required services for MariaDB using systemctl command

command:  
sudo systemctl start mariadb
sudo systemctl enable mariadb
enabling-services-for-mariadb

enabling services for MySQL (MariaDB)

Step 3: Verify MySQL Installation

To verify MySQL installation, use the –version command.

command : mysql --version
verifying-mysql-installation

verifying MySQL installation

3. Installing PHP

Step 1: Install PHP

On Ubuntu/Debian-basedFedora-based systems

command : sudo apt install php -y

On Fedora-basedRHEL-based systems

command : sudo dnf install php -y

On RHEL-based systems

command : sudo yum install php -y
installing-php

Installing PHP

Step 2: Verify installation

To verify php installation, use the –version command.

command : php --version  
verify-php

Verifying php

Conclusion

In this article, we have installed and configured all necessary packages to get the LAMP stack working across popular Linux distributions like Ubuntu, Fedora, and RHEL. No, we can create interactive and wholesome websites. All the packages used are open-source, which makes it a cost-effective and flexible web development solution.

FAQs on How to Set Up a LAMP Stack in Linux

Is there a graphical user interface (GUI) for installing LAMP?

While most installations rely on the command line, some distributions might offer GUI tools to assist with LAMP setup.

Is there a LAMP Stack alternative?

Yes, other open-source software combinations like LEMP (Linux, Nginx, MySQL/MariaDB, PHP) are also popular choices.

What’s the next step after setting up LAMP?

With LAMP up and running, you can start developing your web application using PHP and MySQL to manage dynamic content.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads