Home / Linux / How to Install Apache on Ubuntu and CentOS/RHEL

How to Install Apache on Ubuntu and CentOS/RHEL

Install Apache step by step on Ubuntu/Debian and CentOS/RHEL/Rocky/AlmaLinux, open firewall ports, start the service, and verify.

Views: 21 Unique: 16 Updated: 2026-03-22

What this is

This guide shows how to install and run the Apache web server on the most common Linux families.

What it is for

  • Host websites and web applications
  • Serve static files and reverse proxy (in some setups)

Prerequisites

  • SSH access + sudo
  • A domain (optional) or just use the server IP

Step-by-step by distribution

A) Ubuntu/Debian

A1) Install Apache

sudo apt update
sudo apt install -y apache2

A2) Enable and start

sudo systemctl enable --now apache2

A3) Open firewall (if UFW)

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw status

A4) Verify service

sudo systemctl status apache2 --no-pager

B) CentOS/RHEL/Rocky/AlmaLinux

B1) Install Apache (httpd)

sudo dnf install -y httpd

B2) Enable and start

sudo systemctl enable --now httpd

B3) Open firewall (firewalld)

sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --reload

B4) Verify service

sudo systemctl status httpd --no-pager

Final verification

From your browser:

http://YOUR_SERVER_IP

Or from the server:

curl -I http://127.0.0.1

Warnings & notes

  • Apache service name is apache2 on Ubuntu/Debian and httpd on RHEL-based.

Conclusion

Apache is installed and serving traffic. Next steps are creating virtual hosts and enabling HTTPS.

Back to category