Complete guide to install and configure the Apache HTTP Server on Linux

Introduction

The Apache HTTP Server, commonly known as Apache, is one of the most widely used web servers in the world. Its modular architecture, extensive documentation, and compatibility with virtually any operating system make it an ideal choice for hosting sites and applications in Linux environments. In this article you will learn how to install, configure, and optimize Apache on the most popular distributions, as well as learn security best practices and troubleshooting.

System Preparation

Before installing Apache, it is recommended to update the package repository and ensure the user has sudo privileges. On Debian-based distributions run sudo apt update && sudo apt upgrade -y, while on Red Hat and its derivatives use sudo dnf update -y or sudo yum update -y depending on the version. It is also useful to have a text editor such as nano or vim installed to modify configuration files.

Installation on Ubuntu and Debian

On Ubuntu/Debian the package is named apache2. Installation is straightforward:

  • Run sudo apt install apache2 -y
  • Verify the service is active with sudo systemctl status apache2
  • If not active, start it and enable it for boot: sudo systemctl start apache2 and sudo systemctl enable apache2

Once installed, open a browser and go to http://localhost or the server’s IP address; you should see Apache’s default page indicating everything is working correctly.

Installation on CentOS, RHEL, and Fedora

In these distributions the package is named httpd. The steps are similar:

  • On Fedora and recent RHEL/CentOS versions use sudo dnf install httpd -y
  • On older CentOS versions use sudo yum install httpd -y
  • Start and enable the service: sudo systemctl start httpd and sudo systemctl enable httpd
  • Check the status with sudo systemctl status httpd

Visiting http://localhost should display Apache’s test page.

Basic Configuration

The main configuration files are located in /etc/apache2 (Debian/Ubuntu)