Setup Apache Web Server on RHEL and CentOS7

Introduction to Apache Web Server

In this guide let us see how to install Apache Web Server in RHEL 7, Centos 7, Oracle Linux 7. By following we are going to cover most of all Apache-related topics. We are about to use Apache 2.4 version in this guide.

Below articles are related to Apache topic.

Installing Packages

To install the Apache server we need to install with httpd package.

# yum install httpd -y
Transaction test succeeded
 Running transaction   
     Installing : httpd-2.4.6-45.el7.x86_64   
     Verifying  : httpd-2.4.6-45.el7.x86_64
     httpd.x86_64 0:2.4.6-45.el7 
[root@rhel ~]#

Once done with installation we can verify using yum or rpm query.

# yum list installed | grep httpd
# rpm -qa | grep httpd

Apache Configuration file location

By default, the apache configuration file will be underlying under below location.

# ls -lthr /etc/httpd/conf/httpd.conf
[root@rhel ~]# ls -lthr /etc/httpd/conf/httpd.conf
-rw-r--r--. 1 root root 12K Aug  3  2016 /etc/httpd/conf/httpd.conf 
[root@rhel ~]#

Knowing default welcome page config location

Once we start the apache service we will get a welcome page in the browser while navigating to Apache server using IP or localhost, that information is coming from below file welcome.conf.

File userdir.conf which used to define user home directory as default webroot document for a user.

# ls -lthr /etc/httpd/conf.d/
[root@rhel ~]# ls -lthr /etc/httpd/conf.d/
 total 16K
 -rw-r--r--. 1 root root  516 Aug  3  2016 welcome.conf
 -rw-r--r--. 1 root root 1.3K Aug  3  2016 userdir.conf 
 -rw-r--r--. 1 root root 2.9K Aug  3  2016 autoindex.conf 
 -rw-r--r--. 1 root root  366 Aug  3  2016 README 
[root@rhel ~]#

Location of Apache modules configs

These modules are imported into Apache configuration by using .conf files it will be defined by the following directive.

Include conf.modules.d/*.conf
[root@rhel ~]# ls -lthr /etc/httpd/conf.modules.d/ 
 total 28K 
 -rw-r--r--. 1 root root  451 Aug  3  2016 01-cgi.conf 
 -rw-r--r--. 1 root root   88 Aug  3  2016 00-systemd.conf -rw-r--r--. 1 root root  957 Aug  3  2016 00-proxy.conf 
 -rw-r--r--. 1 root root  742 Aug  3  2016 00-mpm.conf 
 -rw-r--r--. 1 root root   41 Aug  3  2016 00-lua.conf 
 -rw-r--r--. 1 root root  139 Aug  3  2016 00-dav.conf 
 -rw-r--r--. 1 root root 3.7K Aug  3  2016 00-base.conf 
[root@rhel ~]#

To list more modules we can locate it under /etc/httpd/modules/ this location soft linked to /usr/lib64/httpd/modules.

# ls -lthr /etc/httpd/modules/

Output truncated due to long listed output.

[root@rhel ~]# ls -lthr /etc/httpd/modules/
 total 2.5M 
-rwxr-xr-x. 1 root root  20K Aug  3  2016 
-rwxr-xr-x. 1 root root  15K Aug  3  2016 
-rwxr-xr-x. 1 root root  11K Aug  3  2016 
-rwxr-xr-x. 1 root root  15K Aug  3  2016 
-rwxr-xr-x. 1 root root  11K Aug  3  2016 
-rwxr-xr-x. 1 root root  15K Aug  3  2016 
-rwxr-xr-x. 1 root root  11K Aug  3  2016

Location of log files

Under Apache configuration file it will be defined as follows, It will be logged with only warnings, we can change the logging mode as per our requirement.

ErrorLog "logs/error_log"
LogLevel warn
CustomLog "logs/access_log" combined

Location as follows

# ls -lthr /var/log/httpd/
[root@rhel ~]# ls -lthr /var/log/httpd/ 
total 8.0K
-rw-r--r--. 1 root root 2.4K Nov 24 09:48 error_log 
-rw-r--r--. 1 root root 2.2K Nov 24 09:48 access_log 
[root@rhel ~]#

Knowing PID file location of Apache

PID file of Apache service will be under /var/run/httpd/ in case we need to clear PID file below is the location where we need to look for PID files.

# ls -lthr /var/run/httpd/
[root@rhel ~]#  ls -lthr /var/run/httpd/ 
 total 8.0K 
drwx------. 2 apache apache 40 Aug  3  2016 htcacheclean 
-rw-r--r--. 1 root   root    8 Nov 24 10:15 authdigest_shm.2708 
-rw-r--r--. 1 root   root    5 Nov 24 10:15 
[root@rhel ~]#

Apache default important directives

Below are few of default directives which we need to know in Apache web server, these directives will be covered in next upcoming guides.

# egrep -w --color '^Listen|^ServerRoot|^ServerAdmin|^User|^Group|^Include' /etc/httpd/conf/httpd.conf
[root@rhel ~]# egrep -w --color '^Listen|^ServerRoot|^ServerAdmin|^User|^Group|^Include' /etc/httpd/conf/httpd.conf  
 ServerRoot "/etc/httpd" 
 Listen 80 Include conf.modules.d/*.conf 
 User apache 
 Group apache 
 ServerAdmin root@localhost 
[root@rhel ~]#

Managing Apache service

To start, stop, restart we can use two methods.
To start the Apache service we can use two methods.

# apachectl start
# apachectl restart
# apachectl stop
# systemctl start httpd
# systemctl restart httpd
# systemctl stop httpd

To make any changes without restarting service and it should allow the existing apache request we can use graceful option by following apachectl.

# apachectl graceful

To make the service persistent during reboot

# systemctl enable httpd

Firewall rules for Apache

If the server enabled with firewalld service we need to allow the HTTP and HTTPS traffic as shown below.

# firewall-cmd --add-service=http --permanent
# firewall-cmd --add-service=https --permanent
# firewall-cmd --list-all
[root@rhel /]# firewall-cmd --add-service=http --permanent
 [root@rhel /]# firewall-cmd --add-service=https --permanent 
[root@rhel /]# firewall-cmd --list-all 
 public (active)   
   target: default
   icmp-block-inversion: no   
   interfaces: ens33   
   services: dhcpv6-client http https ssh   
   ports: 514/tcp   
   masquerade: no   
   rich rules: 
[root@rhel /]#

That’s it, for installing and looking into Apache configuration, By following we are about to see most of the apache configurations and setups.


Apache web server is one of the very popular web servers for a long time, most of the well known popular websites are hosted on Apache webserver. Hope above guide through important configurations files and steps to configure the apache helps you. Subscribe to our newsletter and stay connected.