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.
To install the Apache server we need to install with httpd package.
# yum install httpd -y
# 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
After the installation, we need to locate the configuration file for apache. It will be located under /etc/httpd/conf/.
# 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 ~]#
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 web root 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 ~]#
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
By default Apache configuration defined with below location for saving there access and error logs.
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
# 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 ~]#
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 ~]#
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 ~]#

To start, stop, restart we can use two methods.
To start the Apache service we can use two methods.
# apachectl start
# systemctl start httpd
To restart
# apachectl restart
# systemctl restart httpd
To stop the Apache service
# apachectl stop
# 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
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.
Babin Lonston
Overall 13+ Years of experience in IT field, 7+ years of experience in Linux administration with Virtualization & Cloud technologies. Love documentation and being Numismatics for a long time.

Creating ASM disks using SAN disk through multipath in Oracle Database Linux Servers

Previous article

35 examples of tcpdump commands in Linux

Next article

You may also like


Leave a reply

Your email address will not be published.