Getting familiar with Apache Web Server configuration files

Share on:

Apache is a very well known web server which used to serve more than half of all the active websites. In this article, we will explore the general configuration files and options that can be controlled within an Apache web server. Here, we will follow the Ubuntu/Debian structure of Apache files.

Installing Apache on Linux (Ubuntu and Debian)

In case if you have not installed the Apache yet, you can install it now by using the following commands:

sudo apt-get update

sudo apt-get install apache2

Apache File distribution in Ubuntu and Debian

On Linux based systems on Ubuntu and Debian, you can find the main configuration files of Apache within the folder “/etc/apache2″ :

Use the following commands to see the file distribution:

  • cd /etc/apache2
  • ls -F

Apache File distribution in Ubuntu and Debian

Let’s get familiar with these locations in the directory:

  • apache2.conf: This is the main server configuration file. Most of the configurations can be done from this file alone. However, it is recommended to use separate, designated files for simplicity and backup. With this file, you can configure the defaults and it acts as a central point of access for the server that reads the configuration details.
  • ports.conf: In this file, you can specify the ports that virtual hosts would listen on. You should take special care to check if this file is correct when you are configuring SSL.
  • conf.d/: This directory controls some specific aspects of the Apache configuration. For example, it can also be used to define SSL configuration and default security configurations.
  • sites-available/: It contains the greater part of the virtual host files that characterize different sites. It will decide up which content gets served for which request. These are accessible setups, not dynamic configurations.
  • sites-enabled/: This directory sets up which virtual host definitions are really being utilized. Ordinarily, it comprises of typical connections to files characterized in the “sites-available”.
  • mods-[enabled,available]/: These directories work similarly as the sites directories, but they additionally define modules that can be loaded instead.

The Apache2.conf File

This file can be found in the directory “/etc/apache2/apache2.conf”. It holds the main configuration details for your Apache server. The file is sectioned into three main parts:

  • Global Apache server process configuration
  • Default server configuration, and
  • Virtual Hosts configuration

In Ubuntu and Debian based Linux systems, the most of the file is for global definitions. The default server configuration and virtual hosts can be handled at the end, by using the “Include …” directive. Here, we will focus on the Apache global settings.

Global Configuration Section

You can use this section to configure some options that control the working of Apache works as a whole. There are few useful options that you may want to learn about in this section:

  • Timeout

It defines the maximum time (in seconds) withing which the server has to fulfill a request. By default, it is set to “300″, which means that the server has a maximum of 300 seconds to fulfill each request.

  • KeepAlive

It this option, is set to “On”, it will allow each connection on the server to remain active to handle multiple requests from the same client. Setting it to “Off” will want each request to establish a new connection. Keeping it off will result in unnecessary overhead to the server.

  • MaxKeepAliveRequests

This section controls how many separate requests can be handled by a connection before dying. Keeping its value to a higher number high means the Apache will serve content to each client more effectively. If the value 0, it will allow Apache server to serve a unlimited number of requests for each connection.

  • KeepAliveTimeout

It specifies how long the server will wait for the next request after finishing the last one. If it reaches the timeout threshold, the connection will die. The next time when a content is requested, the server will establish a new connection to server that request.

  • MPM Configuration

This section specifies the MPM (Multi-Processing Module) configuration options. You can check which section your Apache installation was compiled with on your system by visiting into the terminal and typing:

     apache2 -l 

Apache configuration files

This is how the Apache configuration files are distributed and perform their assigned task. You must always read about all these files and their configuration before attempting any modification. Furthermore, do not forget to take a backup before editing them. You can read more about how to edit a file on Linux from here.

For more command line operations such as zipping or unzipping files on Linux, Installing phpMyAdmin on Linux, you can have a look at our guides.

Share on: