VOOZH about

URL: https://www.geeksforgeeks.org/techtips/how-to-set-up-a-lamp-stack-in-linux/

⇱ How to Set Up LAMP Stack in Linux? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Set Up LAMP Stack in Linux?

Last Updated : 23 Jul, 2025

Setting up a LAMP stack in Linux is a fundamental task for creating a powerful web server environment. LAMP stands for Linux, Apache, MySQL, and PHP, and together they provide a robust platform for developing and deploying web applications. This guide will walk you through the process of installing and configuring each component of the LAMP stack on a Linux system, ensuring you have a fully functional web server ready for your projects.

How to Install LAMP Stack in Linux?

We must install Apache web server, MySQL, and PHP to set up LAMP Stack in Linux. Before proceeding to see all the step-by-step process directly. Let's first check all the prerequisites to install the LAMP stack in Linux.

Prerequisites to Install LAMP Stack

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.

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

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

command : sudo dnf update -y

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
πŸ‘ Set Up LAMP Stack in Linux
Upgrading System

1. Installing Apache Web Server

Step 1: Install Apache Web Server using the package manager

Fedora-based

Command: sudo apt install apache2 -y

RHEL-based

Command: sudo dnf install httpd -y
Command: sudo yum install httpd -y
πŸ‘ Set Up LAMP Stack in Linux
Installing Apache Web Service

Step 2: Enable services

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

Command: sudo systemctl enable apache2
Command: sudo systemctl enable httpd.service
Command: sudo systemctl enable httpd.service
πŸ‘ Set Up LAMP Stack in Linux
starting services for the Apache Web Server

Step 3: Verify Apache Web Server Installation

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

Command: apache2 -v
Command: httpd -v
Command: httpd -v
πŸ‘ Set Up LAMP Stack in Linux
Verifying Apache web server installation

2. Installing MySQL (MariaDB)

Step 1: Install MariaDB using the package manager

Command: sudo apt install mariadb-server mariadb-client
Command: sudo dnf install mariadb mariadb-server -y
Command: sudo yum install mariadb mariadb-server -y
πŸ‘ Set Up LAMP Stack in Linux
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
πŸ‘ Set Up LAMP Stack in Linux
enabling services for MySQL (MariaDB)

Step 3: Verify MySQL Installation

To verify MySQL installation, use the --version command.

Command: mysql --version
πŸ‘ Set Up LAMP Stack in Linux
verifying MySQL installation

3. Installing PHP

Step 1: Install PHP

command : sudo apt install php -y
command : sudo dnf install php -y
command : sudo yum install php -y
πŸ‘ Set Up LAMP Stack in Linux
Installing PHP

Step 2: Verify installation

To verify php installation, use the --version command.

Command: php --version 
πŸ‘ Set Up LAMP Stack in Linux
Verifying php

Conclusion

Setting up a LAMP stack in Linux is a straightforward process that provides a solid foundation for web development. By following the steps outlined in this guide, you can successfully install and configure Linux, Apache, MySQL, and PHP on your server. With a properly set up LAMP stack, you'll be well-equipped to develop, test, and deploy web applications efficiently and effectively.

Comment
Article Tags:
Article Tags: