Post

How to Install Apache Web Server on Ubuntu and RHEL/Rocky Linux

How to Install Apache Web Server on Ubuntu and RHEL/Rocky Linux

How to Install Apache Web Server on Ubuntu and RHEL/Rocky Linux

Apache HTTP Server is one of the most popular and reliable web servers used worldwide. This tutorial covers the installation and basic configuration steps for Apache on Ubuntu and RHEL/Rocky Linux distributions.


Installing Apache on Ubuntu

Step 1: Update Package Index

Open a terminal and update your package list to ensure you get the latest version:

1
sudo apt update

Step 2: Install Apache

Install the Apache2 package with:

1
sudo apt install apache2 -y

This installs Apache along with all required dependencies.

Step 3: Adjust Firewall Settings

Ubuntu uses UFW (Uncomplicated Firewall) by default. To allow HTTP traffic on port 80, enable the Apache profile:

1
sudo ufw allow 'Apache'

You can check available profiles with:

1
sudo ufw app list

Profiles include:

  • Apache (port 80)
  • Apache Full (ports 80 and 443)
  • Apache Secure (port 443 only) For a fresh install without SSL, allow only port 80.

Step 4: Verify Apache Installation

Open a web browser and visit your server’s IP address or domain name:

1
http://your_server_ip

You should see the default Apache welcome page, confirming the server is running.

Step 5 (Optional): Enable Apache to Start on Boot

Apache usually starts automatically, but to ensure it starts on boot:

1
sudo systemctl enable apache2

Step 6 (Optional): Check Apache Status

Verify Apache is active and running:

1
sudo systemctl status apache2

Installing Apache on RHEL / Rocky Linux

Step 1: Update Your System

Use the package manager to update your system packages:

1
2
sudo yum update -y        # For RHEL 7/8
sudo dnf update -y        # For Rocky Linux 8/9 and RHEL 8/9

Step 2: Install Apache (httpd)

Install the Apache package named httpd:

1
2
sudo yum install httpd -y   # RHEL 7/8
sudo dnf install httpd -y   # Rocky Linux 8/9 and RHEL 8/9

Step 3: Start and Enable Apache Service

Start the Apache service and enable it to start on boot:

1
2
sudo systemctl start httpd
sudo systemctl enable httpd

Step 4: Configure Firewall

Allow HTTP traffic on port 80:

1
2
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload

Step 5: Verify Apache Installation

Open a browser and navigate to your server’s IP address:

1
http://your_server_ip

You should see the Apache test page indicating the server is running.


Additional Configuration Tips

  • Apache configuration files are located at /etc/apache2/ on Ubuntu and /etc/httpd/ on RHEL/Rocky.
  • The default web root directory is /var/www/html.
  • To host your own website, place your files in the web root or configure virtual hosts.
  • For enabling HTTPS, you can install and configure SSL certificates (e.g., via Let’s Encrypt).

Summary Table

Step Ubuntu (apt) RHEL/Rocky (yum/dnf)
Update system sudo apt update sudo yum update -y / sudo dnf update -y
Install Apache sudo apt install apache2 -y sudo yum install httpd -y / sudo dnf install httpd -y
Start \& enable service sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl start httpd
sudo systemctl enable httpd
Configure firewall sudo ufw allow 'Apache' sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
Verify Visit http://server_ip Visit http://server_ip

This tutorial provides a straightforward way to get Apache up and running on both Ubuntu and RHEL/Rocky Linux systems, suitable for development and basic web hosting needs.

This post is licensed under CC BY 4.0 by the author.

Trending Tags