How To Install Apache (HTTPD) On CentOs 7
Enjoying this content? Subscribe to the Channel!
From Zero to Web Server: Installing and Configuring Apache (HTTPD) on CentOS 7
Hello tech enthusiasts, and welcome back to Darren’s Tech Tutorials!
Getting your own web server up and running might sound complicated, but with CentOS 7 and the powerful, reliable Apache HTTP Server, it’s surprisingly straightforward. Apache is the foundation of countless websites globally, and today, we are going to walk through the exact steps to install it, start the service, and ensure your server is accessible to the world.
Whether you’re setting up a testing environment or launching a small website, this guide provides the clear, actionable commands you need. Let’s get started!
(P.S. Need quick reference? Don’t forget to grab your free Linux command cheat sheet!)
Prerequisites and Initial Checks
Before we dive into the installation, you need to ensure you have a running CentOS 7 instance. If you need help installing CentOS 7, please check out our previous tutorial on the channel.
We also highly recommend using an SSH client like PuTTY (if you are connecting remotely) to easily copy and paste commands, preventing typos.
Note: Apache is referred to by its package name, httpd, in CentOS and Red Hat-based distributions. When we run commands, we will be using httpd.
Step 1: Installing the Apache Web Server
The very first step is to use the yum package manager to fetch and install the httpd package. This command downloads all necessary files and dependencies onto your CentOS machine.
Run the following command in your terminal:
sudo yum install httpd
You will likely be prompted to confirm the installation by pressing y. Once confirmed, the system will install Apache and all its components.
Step 2: Starting and Checking the Apache Service
Installation is only half the battle! We need to manually start the service for the first time. We will use the systemd manager (via the service command) to handle the process.
A. Start the Service
Execute the following command to bring your web server online:
sudo service httpd start
B. Verify the Service Status
To ensure that Apache has started correctly and is actively running, check its status.
sudo service httpd status
You should see output indicating that the service is active (running). If you see anything else, stop and double-check the installation step.
Step 3: Enabling Apache to Start on Boot
If your CentOS server were to reboot right now, Apache would not automatically restart, meaning your website would go offline until you manually started the service again. We definitely don’t want that!
We need to enable the service permanently so it survives system reboots. We achieve this using the chkconfig command:
sudo chkconfig httpd on
This ensures that the httpd service is enabled to run automatically whenever the system starts up. Your web server is now persistent!
Step 4: Configuring the Firewall (The Essential Step!)
This is arguably the most critical step. By default, CentOS 7 is security-focused and uses FirewallD to block incoming connections on most ports—including port 80, the standard port for web traffic (HTTP).
If you skip this step, Apache will be running successfully on your machine, but no external user (i.e., someone trying to reach your website) will be able to connect!
First, let’s quickly check the status of your firewall service:
sudo service firewalld status
Assuming the firewall is running, we now need to explicitly tell it to allow incoming traffic on port 80 (TCP).
A. Open Port 80 Permanently
Run the following command to open port 80 and make the change permanent (it will persist after a firewall reboot):
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
You should receive a success message.
B. Apply the Changes
The --permanent flag adds the rule to the configuration file, but the firewall is still using the old ruleset. We must reload the firewall for the new rule to take effect immediately:
sudo firewall-cmd --reload
Again, you should receive a success message.
Final Verification: Testing Your Web Server
Congratulations! Your Apache web server is now fully installed and configured.
To test that everything worked, open a web browser on a separate machine (or your host machine if you are using a VM) and type in the IP address of your CentOS 7 server.
If successful, you should see the default CentOS 7 Test Page! This page confirms that Apache is running and the firewall is configured correctly to allow external access.
Next Steps
You now have a powerful foundation for hosting web content. The default files for your server are located in /var/www/html/. Start customizing your site by editing the files in that directory!
We hope this step-by-step guide made the process of installing Apache on CentOS 7 clear and painless. This is a fundamental skill for any server administrator, and you nailed it!
If you found this tutorial helpful, please smash that Like button, subscribe to Darren’s Tech Tutorials for more clear guides, and let us know in the comments what you’re planning to build with your new server! Happy hosting!