Installing Apache Web (HTTP/HTTPS) Server on CentOS7

Install Apache Web Server on CentOS

Looking to establish a reliable and secure web presence? Learn how to Install Apache web server on CentOS and unlock the potential of your website today.

Table of Contents


The Apache web server, commonly referred to as an HTTP/HTTPS server, is one of the most popular and widely used web servers in the world. In this tutorial, we’ll explore how to Install Apache web server on CentOS, a popular Linux distribution used for server applications.

Whether you’re a beginner looking to get started or an experienced web developer seeking to enhance your skills, this guide will provide you with everything you need to know to set up a secure web server on CentOS.

Brief History

The Apache Software Foundation (ASF) was founded in March 25, 1999 (when it was officially incorporated). However, the Apache HTTP server development began some six years earlier in February 1993 with developers that would eventually be known as the Apache Group.

Developers and Contributors

The initial members of the Apache Software Foundation consisted of the Apache Group: Brian Behlendorf (as the primary developer/contributor), Ken Coar, Miguel Gonzales, Mark Cox, Lars Eilebrecht, Ralf S. Engelschall, Roy T. Fielding, Dean Gaudet, Ben Hyde, Jim Jagielski, Alexei Kosut, Martin Kraemer, Ben Laurie, Doug MacEachern, Aram Mirzadeh, Sameer Parekh, Cliff Skolnick, Marc Slemko, William (Bill) Stoddard, Paul Sutton, Randy Terbush and Dirk-Willem van Gulik.

ASF Mission

As of 2021, the ASF decentralized open-source community consists of about 1000 members and several open-source projects. Some of ASF’s main objectives include but are not limited to: providing legal protection to volunteers working on Apache projects and–prevent the Apache brand from being used by other organizations without permission.


This install procedure assumes that you already have RHEL/CentOS7 installed and updated. If not, install the CentOS7 operating system (OS) and revisit this page to proceed with the HTTP server setup. Also, you will need to have privileged access to become the root user.

First things first, it’s always best practice to update your system before proceeding with any package install. Run the following on the command-line:

					# yum update -y

Install Apache Web Server on CentOS7

Now that our CentOS7 is up-to-date, we can proceed with installing the Apache HTTP package and associated dependencies.

					# yum install httpd 
Loaded plugins: fastestmirror, langpacks 
Loading mirror speeds from cached hostfile  
* base:  
* epel:  
* extras:  
* remi-php70:  
* remi-php73:  
* remi-safe:  
* updates: 
Resolving Dependencies 
--> Running transaction check 
---> Package httpd.x86_64 0:2.4.6-97.el7.centos.2 will be reinstalled
--> Finished Dependency Resolution 

Dependencies Resolved
Package                      Arch                    Version                        Repository                Size 
Installing:  httpd           x86_64                  2.4.6-97.el7.centos.2          updates                   2.7 M 

Transaction Summary
Reinstall  1 Package 

Total download size: 2.7 M 
Installed size: 9.4 M 
Is this ok [y/d/N]: Y

After the installation is complete, there are few more steps left to do to ensure our web server is operational.

Configuration: Apache HTTP Service & Firewall Settings

First, lets test things out and ensure the httpd service starts up properly for the first time. We can also enable the service to start up automatically on boot up.

					# systemctl start httpd; systemctl enable httpd; systemctl status httpd
● httpd.service - The Apache HTTP Server 
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) 
  Drop-In: /usr/lib/systemd/system/httpd.service.d 
   Active: active (running) since Tue 2021-11-16 03:50:34 UTC; 14s ago Docs: man:httpd.service(8) 
   Main PID: 94043 (httpd) 
   Status: "Running, listening on: port 443, port 80" 
   Tasks: 213 (limit: 12436) 
   Memory: 25.4M 
   CGroup: /system.slice/httpd.service 
           ├─94043 /usr/sbin/httpd -DFOREGROUND 
           ├─94044 /usr/sbin/httpd -DFOREGROUND 
           ├─94045 /usr/sbin/httpd -DFOREGROUND 
           ├─94046 /usr/sbin/httpd -DFOREGROUND 
           └─94047 /usr/sbin/httpd -DFOREGROUND
...output omitted...

Firewall Setup

Now, we set the firewall rules to allow http and https traffic (we do plan on securing our web server so, HTTPS and SSL certs…but for now, lets proceed). By default, the built-in CentOS7 firewall blocks http/https traffic.

					# firewall-cmd --zone=public --permanent --add-service=http 

Allow HTTPS service by running the following command:

					# firewall-cmd --zone=public --permanent --add-service=https 

Reload the firewall settings:

					# firewall-cmd --reload 

Verify the firewall settings:

					# firewall-cmd --list-all 
public (active) 
  target: default 
  icmp-block-inversion: no 
  interfaces: enp1s0 
  services: cockpit dhcpv6-client http https ssh 
  masquerade: no 
  rich rules:

Launching Test Page

Enter the IP address (not the most secure option) or server domain name (preferred) into the address bar of your favorite browser! If all goes as planned, you should see the Apache Test Page (below): http://localhost or http://<ip-address>

Photo by admingeek from Infotechys

Securing the Web Server

Now that we’ve established a running HTTP web server, we can secure it in a few additional steps.

Step 1: Obtain SSL Certificate

Obtain an SSL/TLS certificate for your domain. You can get a free SSL/TLS certificate from Let’s Encrypt or purchase one from a trusted Certificate Authority (CA).

Step 2: Configure Server for HTTPS

This involves editing your server configuration files to enable HTTPS, specifying the location of your SSL/TLS certificate and private key, and setting up redirects from HTTP to HTTPS.

Install mod SSL

Begin with installing the Apache module for enabling SSL.

					# yum install mod_ssl

Step 3: Install Certs and Keys

Once you have obtained your SSL/TLS certificate, copy the certificate and private key to the appropriate directories on your server. The certificate file should be saved as /etc/pki/tls/certs/yourdomain.crt, and the private key file should be saved as /etc/pki/tls/private/yourdomain.key. You may need to create these directories if they do not exist.

					# sudo mkdir -p /etc/pki/tls/certs; sudo mkdir -p /etc/pki/tls/private

# sudo cp yourdomain.crt /etc/pki/tls/certs/
# sudo cp yourdomain.key /etc/pki/tls/private/

Edit your Apache configuration file (/etc/httpd/conf/httpd.conf) to enable HTTPS. Add the following lines to the file:

					LoadModule ssl_module modules/
Listen 443 https

Step 4: Configure virtual host

Configure your virtual host to use HTTPS. Locate your virtual host configuration file (/etc/httpd/conf.d/yourdomain.conf) and add the following lines to the file:

					<VirtualHost *:443>
    DocumentRoot /var/www/
    SSLEngine on
    SSLCertificateFile /etc/pki/tls/certs/yourdomain.crt
    SSLCertificateKeyFile /etc/pki/tls/private/yourdomain.key

The Breakdown

Replace with your actual domain name, and DocumentRoot with the path to your website’s root directory.

  • Restart Apache using the following command: sudo systemctl restart httpd
  • Test your HTTPS website by accessing it in a web browser using You should see a green padlock icon in the address bar, indicating that your website is using a secure HTTPS connection.


That’s it! Your website is now hosted on an HTTPS web server, ensuring that all data exchanged between your server and your users is encrypted and secure. Was this article helpful to you? If so, leave us a comment below and share!

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *