• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Beginners guide to Apache HTTP Server – Installation and Configuration

by admin

Apache HTTP server

The Apache HTTP Server, an open-source web server developed by the Apache Software Foundation. The Apache server is used to host web content. It responds to requests for content from web browsers, such as Internet Explorer and Firefox.

Note : The post uses RHEL/CentOS 7 distribution to install and configure the Apache server. Although the start/stop/install commands may differ but the configuration steps are same in all the linux distribution

Installing Apache

To configure your system as a web server, begin by installing the httpd software package.

# yum install httpd

Use the systemctl utility to enable the HTTP daemon to start at boot time and also to start the daemon immediately.

# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
# systemctl start httpd

Configuration files

The main configuration file for Apache is /etc/httpd/conf/httpd.conf. An auxiliary directory, /etc/httpd/conf.d, also exists to store configuration files that are included in the main configuration file. Configuration files that load modules are in the /etc/httpd/conf.modules.d directory.

New apachectl subcommands in CentOS / RHEL 7

A new apachectl sub-commands are available in CentOS / RHEL 7. The following example uses the configtest subcommand to check the configuration for possible errors.

# apachectl configtest

Use the graceful subcommand to reload the configuration without affecting active requests.

# apachectl graceful

Configuring Apache

The main configuration file for Apache is /etc/httpd/conf/httpd.conf. Apache runs as installed, but you can modify configuration directives in this file to customize Apache for your environment. Some of these directives are described in the post below.

Apache HTTP server – most commonly used configuration directives

Testing Apache HTTP server

You can confirm that Apache is working by pointing a browser on the local system to http://localhost as shown in the picture below. You can also point a browser to http:// followed by the IP Public address of the server or the ServerName directive that you specified in the configuration file. The test page shown below confirms the functioning Apache HTTP server.

apache http server installation and configuration CentOS RHEL 7

To test the display of actual content, create an HTML file named index.html in the directory specified by the DocumentRoot directive (the default directory is /var/www/html). Apache automatically displays the index.html file in this directory, if it exists.

Apache Containers

Apache containers are special configuration directives that group other directives. The containers use XML-style tags, meaning that the beginning of a container is <name> and the end is </name>. An index of all the container directives is available at http://httpd.apache.org/docs/current/sections.html. Refer the post below to get the most commonly used apache containers.

Apache HTTP server – most commonly used containers (special configuration directives)

Apache Virtual Hosts

Apache supports virtual hosts, meaning that a single Apache server can respond to requests directed to multiple IP addresses or host names. Each virtual host can provide content and be configured differently.
You can configure virtual hosts in two ways:
1. IP-based Virtual Hosts (host-by-IP)
2. Name-based Virtual Hosts (host-by-name)

host-by-IP
With host-by-IP, each virtual host has its own IP address and port combination. The Apache web server responds to the IP address that the host resolves as. Host-by-IP is required for serving HTTPS requests due to restrictions in the Secure Sockets Layer (SSL) protocol.

host-by-name
With host-by-name, all virtual hosts share the common IP address. Apache responds to the request by mapping the host name in the request to ServerName and ServerAlias directives in the particular virtual host’s configuration file.

Use the <VirtualHost host-name> container to implement virtual hosts. After the first VirtualHost is defined, all of the content served by Apache must also be moved into virtual hosts.

The following example is a simple name-based virtual hosts configuration:

<VirtualHost *:80>
      ServerName example1.com
      ServerAlias www.example1.com
      DocumentRoot /var/www/example1
      ErrorLog example1.error_log
</VirtualHost>
<VirtualHost *:80>
      ServerName example2.com
      ServerAlias www.example2.com
      DocumentRoot /var/www/example2
      ErrorLog example2.error_log
</VirtualHost>

Filed Under: CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. How to truncate /var/log/lastlog File
  2. aspell: command not found
  3. lvdisplay error: “Failed to create directory /var/lock/lvm. File-based locking initilisation failed.”
  4. How to make alias command work in bash script or bashrc file
  5. How To Configure 802.1q VLAN On NIC On CentOS/RHEL 7 and 8
  6. Understanding OS load average and run queue/blocked queue in terms of CPU utilization in Linux
  7. How to disable “sudo su” for users in sudoers configuration file
  8. cuyo: command not found
  9. lsns Command Examples in Linux
  10. How to manage File and Directory Permissions/Ownerships in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • pw-cat Command Examples in Linux
  • pvs: command not found
  • pulseaudio: command not found
  • pulseaudio Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright