How to Install Apache (HTTPD) on CentOS 9 / Redhat 9 / Fedora
Enjoying this content? Subscribe to the Channel!
Mastering Web Servers: A Step-by-Step Guide to Installing Apache (HTTPD) on CentOS 9
Introduction: Why Apache on CentOS 9 is Your Next Project
Welcome back to Darren’s Tech Tutorials!
If you’re ready to host your own website, build a local testing environment, or just deepen your knowledge of enterprise-grade Linux servers, installing a robust web server is the perfect place to start. Today, we’re tackling the setup of Apache HTTP Server (known simply as httpd in Red Hat systems) on CentOS 9.
Apache is the world’s most widely used web server software, famous for its stability, flexibility, and powerful features. While this guide focuses specifically on CentOS 9, the commands and principles we cover are fully compatible with other Red Hat-based distributions, including RHEL, Fedora, and even many of the lighter derivatives.
We will walk through the entire process, from installation and service management to enabling boot-up persistence and, finally, creating your very own custom web page. Let’s dive in!
Step 1: Preparing Your System and Installing Apache HTTPD
Before we install any new software, it’s always best practice to ensure your system is fully up-to-date. This prevents dependency conflicts and ensures you have the latest security patches.
Update the System
Use the dnf package manager to update your system:
sudo dnf update -y
Install the Apache Package (HTTPD)
In CentOS and other Red Hat-based distributions, the Apache server package is named httpd. Use dnf to install it quickly:
sudo dnf install httpd -y
That’s it! The core software is now installed on your system.
Step 2: Starting and Enabling the Apache Service
Installation is only the first step. Next, we need to use systemctl to manage the service. We must both start the service immediately and enable it so that Apache automatically begins running every time your CentOS machine boots up.
Start the Service
Immediately activate the Apache web server:
sudo systemctl start httpd
Enable the Service
To ensure the service persists across reboots, use the enable command:
sudo systemctl enable httpd
Verify Status
You can check the operational status of the service at any time to ensure it is running correctly:
sudo systemctl status httpd
You should see an output indicating the status is active (running).
Step 3: Configuring the Firewall for Web Traffic
CentOS 9 comes equipped with firewalld enabled by default for enhanced security. This means that even though Apache is running, the server won’t be accessible from external machines until we explicitly allow HTTP (port 80) and HTTPS (port 443) traffic through the firewall.
We need to add these services permanently and then reload the firewall rules:
# Allow HTTP traffic (Port 80)
sudo firewall-cmd --permanent --add-service=http
# Allow HTTPS traffic (Port 443 - essential for modern sites)
sudo firewall-cmd --permanent --add-service=https
# Apply the new firewall rules
sudo firewall-cmd --reload
Step 4: Testing the Default Installation
With the service running and the firewall configured, it’s time to verify that your web server is operational.
Accessing the Server
Open your favorite web browser and navigate to the IP address of your CentOS server.
- If you are testing from the server itself, you can use
http://localhost/ - If you are testing from a separate machine, use the server’s actual IP address (e.g.,
http://192.168.1.15).
You should see the default Apache “Testing 123…” page. This indicates that the server is working perfectly and ready for content!
Step 5: Creating Your Custom Web Page (The Hello World Moment)
The default web content directory for Apache on CentOS is /var/www/html/. Any files placed in this location will be served to the public. To truly confirm control over your server, let’s create a simple custom index.html file.
Navigate to the Web Root
cd /var/www/html/
Create the Custom File
We will use the nano text editor (you may need to install it with sudo dnf install nano -y if it’s not present) to create a new index.html file. This file will overwrite the default test page.
sudo nano index.html
Paste the following simple HTML code into the editor:
<!DOCTYPE html>
<html>
<head>
<title>Darren's Tech Tutorials Server</title>
</head>
<body>
<h1>Success! Apache is Running on CentOS 9!</h1>
<p>This custom page confirms that the installation and configuration worked perfectly. Time to start building!</p>
</body>
</html>
Save the file and exit the editor (Ctrl+X, then Y, then Enter in nano).
Final Verification
Now, refresh your browser page at your server’s IP address. Instead of the default test page, you should see your custom “Success! Apache is Running on CentOS 9!” message!
Conclusion: You Are Now a Web Server Administrator!
Congratulations! You have successfully installed, configured, secured, and customized the powerful Apache web server on your CentOS 9 machine. This critical skill is the foundation for hosting dynamic applications, setting up staging environments, and deepening your understanding of Linux server administration.
Did you find this tutorial helpful? If so, make sure to Like this post and Subscribe to Darren’s Tech Tutorials for more clear, step-by-step guides just like this one!
If you hit any snags during your installation, drop a comment below—I’m always happy to help troubleshoot! Happy hosting!