Installing Apache on Linux is one of the most essential steps for anyone setting up a web server or hosting environment. Apache HTTP Server is an open-source, highly reliable, and widely used web server that powers a significant portion of the internet. Whether you’re building a simple website, deploying web applications, or creating a full LAMP stack, learning how to install Apache on Linux provides a strong foundation for managing and serving content efficiently.
This guide walks you through the complete process of installing, configuring, and verifying Apache on a Linux server. The steps are designed to be simple, clear, and beginner-friendly, so even if you’re new to Linux server administration, you’ll be able to follow along without confusion. By the end, you’ll have a fully functional Apache setup ready to host websites and applications.
Prerequisites
Before you Install Apache on Linux, ensure you have the following:
- A Linux server (Ubuntu, Debian, CentOS, Rocky Linux, AlmaLinux, Fedora, etc.)
- SSH or terminal access to the server
- Sudo or root privileges to install and manage software
- Updated package lists (recommended before installation)
- Basic command-line knowledge for running installation and configuration commands
- Awareness that package names differ by distro:
apache2for Debian/Ubuntuhttpdfor RHEL/CentOS/Fedora
Install Apache HTTP Server on Linux
Below are the commands you’ll use to install Apache on Linux, depending on your distribution. Follow the section that matches your server’s OS.
- Install Apache on Debian/Ubuntu-based Systems
To install Apache on Linux systems like Ubuntu or Debian, run:
sudo apt update
sudo apt install apache2 -y
This installs the apache2 package along with all required dependencies.
- Install Apache on RHEL/CentOS/Fedora-based Systems
For RHEL-based servers, the package name is different. To install Apache on Linux using Yum or DNF, run:
sudo yum install httpd -y
or on newer systems:
sudo dnf install httpd -y
This installs the httpd package and its dependencies.
Start and Enable Apache Service
After you install Apache on Linux, the next step is to start the Apache service and ensure it runs automatically whenever the server boots.
- Start Apache Service
For Debian/Ubuntu systems:
sudo systemctl start apache2
For RHEL/CentOS/Fedora systems:
sudo systemctl start httpd
- Enable Apache to Start on Boot
To make sure Apache starts automatically after every reboot:
Debian/Ubuntu:
sudo systemctl enable apache2
RHEL/CentOS/Fedora:
sudo systemctl enable httpd
This ensures your web server stays active without needing manual intervention each time.