Apache HTTP

Example Apache httpd.conf File and Important Settings

The Apache HTTP Server Project, commonly known as Apache HTTPD or Apache, is an open-source HTTP server that powers a large percentage of web applications. Apache HTTPD is cross-platform and can run on Unix and Windows-based systems.

In this tutorial, we will look at the Apache HTTP configuration, including how it works. We will understand some of the most critical configurations in the file and what they do.

Installing Apache Server

Before we get to the Apache configuration, let us ensure we have it installed and running.

Launch the terminal and use the commands below to install the Apache server on your system:


sudo apt-get update
sudo apt-get install apache2


sudo pacman -Sy
sudo pacman -S apache


sudo yum update
sudo yum install httpd

Where is Apache httpd.conf file?

Depending on the distribution on which you have the Apache server installed, the location of the httpd.conf will vary.

On Debian systems (apache2), the location of the Apache configuration is:


On Fedora/CentOS and other REHL systems, the Apache configuration is in:


Other locations you can check for the apache httpd configuration files are:


Tips for Editing the Apache Configuration

Although the Apache httpd configuration file is easy to edit, it will prevent the webserver from running if you mess up its syntax.

The following are some tips to keep in mind when editing the configuration files.

  1. Ensure to keep a backup copy of the initial httpd.conf file. A backup will allow you to restore and compare the configuration, making troubleshooting easier.
  2. Edit a single block in the apache config file per instance. In simpler terms, edit one setting, save the file and try to start the server. Doing this will help you catch any errors that may keep the server from starting.
  3. When troubleshooting the config file, start with the most recently edited blocks and work your way up to the oldest edit.

Default httpd.conf file

The following is an example of the Apache httpd.conf file with all the default values. You can use this file to restore your settings.

DefaultRuntimeDir ${APACHE_RUN_DIR}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied

<Directory /usr/share>
        AllowOverride None
        Require all granted

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
AccessFileName .htaccess
<FilesMatch "^\.ht">
        Require all denied

LogFormat "%v:%p %h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"" vhost_combined
LogFormat "%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"" combined
LogFormat "%h %l %u %t "%r" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf

NOTE: In the above example httpd.conf file, we have removed the commented documentation. Check the man pages to learn more.

Important httpd.conf file Settings

The following are some of the essential blocks in the httpd.conf file. It is good to note that some of the blocks stated in this section might not be in the default apache config file.

  • AccessFileName – This directive defines the name of the file used for access control information in each directory. The default value is set to .htaccess.
  • AddType – This directive overrides the default MIME type and file extension pair.
  • Listen – The listen directive specifies which port the webserver will listen from for incoming requests. By default, this value is set to port 80 for HTTP and port 443 for HTTPS.
  • LoadModule – The load-module directive is used to load Dynamic Share Objects.
  • Location – The location tags (<Location> and </Location>) are used to create a container for access control based on an URL.
  • MaxClients – This directive defines the limit for the total number of server processes or the number of simultaneously connected clients.
  • VirtualHost – The VirtualHost tag block creates a container for virtual hosts, allowing multiple sites to run in one server. The <VirtualHost></VirtualHost> block can accept other blocks.
  • ServerRoot – This directive is used to define the top-level dir for the website contents. The default value is set to /etc/apache2 or /etc/httpd.
  • ServerName – defines the hostname and port for the server.
  • PidFile – defines the filename for the server PID file. By default, the value is set to /var/run/apache2/apache2.pid or /var/run/httpd/httpd.pid
  • LogLevel – determines the log verbosity level.
  • MaxKeepAliveRequests – this directive defines the maximum number of requests per one persistent connection. The value is set to 100 by default.
  • DocumentRoot – The document root is the directory containing the HTML files served to the clients. This value is set to /var/www/html by default.
  • ErrorLog – The location where the log file is stored. By default, this value is set to /var/log/apache2/erro.log or /var/log/httpd/error.log
  • DirectoryIndex – This directive sets the default page served to the clients when the index location is requested. By default, this value is set to index.html. If no index value is found, the server will list directories (if enabled) or a 403 forbidden error if the directory listing is disabled.
  • Allow – This defines the client given access to a specific directory. The client can be a domain name, IP address, network mask, etc. Works similar to Deny.
  • AllowOverride – This directive determines if the value of a specific directive is overridable in the .htaccess file.
  • AddHandler – The handler extension maps file extensions to their respective handlers. For example, .cgi files can be mapped to a cgi-script handler.


The guide has walked you through the process of managing the Apache httpd configuration. We also outlined some basic settings in the configuration files. Consider the documentation to learn more about the apache config file and how to configure each directive.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list