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.
Table of Content
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
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
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
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
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
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
Step 2: Starting Services for MariaDB
Start required services for MariaDB using systemctl command
command:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Step 3: Verify MySQL Installation
To verify MySQL installation, use the –version command.
command : mysql --version
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
Step 2: Verify installation
To verify php installation, use the –version command.
command : php --version
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.