Search notes:

httpd.conf

httpd.conf is the (default) name for the configuration file for the Apache Webserver. This configuration file contains directives.
A directive is typically one line, but can be extended over multiple lines with the line continuation character \ (as last character on the line).
Comments can be placed with the # symbol.
When the webserver is started, the default name and location of the httpd.conf file can be overridden with the -f option.
When a setting in httpd.conf is changed, the web server needs to be restarted for the changes to take effect.

ServerRoot

The ServerRoot directive specifies the directory under which the server's configuration, error and log files will be written.
TODO: Does it also specify the directory where LoadModule searches for modules?
With an XAMPP installation, this directive might look like this:
ServerRoot "C:/Users/rene/xampp/apache"
For example, the location of the error log file (below ServerRoot) is controlled with the ErrorLog directive:
ErrorLog "logs/error.log"
If not specified in the configuration file, the server root can be specifed with the -d serverroot command line option of httpd.

Listen

Listen specifies the port which the server will listen for HTTP requests:
Listen 80

DocumentRoot

DocumentRoot specifies the top directory from where documents are served to the client.
DocumentRoot "C:/Users/rene/web/httpsdocs"
The DocumentRoot directive might go hand in hand with a <Directory directive:
<Directory "C:/Users/rene/web/httpsdocs">
    Options       Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require       all granted
</Directory>
The value of DocumentRoot can be queried in PHP with $_SERVER['DOCUMENT_ROOT'].

LoadModule / IfModule

LoadModule loads a Dynamic Shared Object (DSO).
LoadModule dir_module modules/mod_dir.so
Directives that need to be executed only if a module was loaded, can be placed within the <IfModule …> directive:
<IfModule dir_module>
    DirectoryIndex index index.php index.html
</IfModule>
An <IfModule …> test can be negated with an exclamation mark:
<IfModule !moduleName>…
IfModule …> tests can be nested.

Define

The Define directive comes in two forms.
In the first form, Define is used boolean. It is equivalent to the -D … command line option of httpd
Define XYZ
If XYZ was defined can then be tested with the <IfDefine XYZ> … </IfDefine> directive.
The second form allows to associate a symbol with a value:
Define USER "rene"
The value of USER is expanded in httpd.conf with ${USER}.
It's possible to define a value with the command line option -D … of httpd.

Scope of directives

By default, a directive controls the behavior of the entire server. However, a directive's scope can be limited in scope with one of the following sections:
In addition, directives that effect directories (and subdirectories) only can be placed into .htaccess files (if a corresponding AllowOverride directive allows to override a setting in .htaccess).

Checking validity of syntax

The -t option of httpd allows to check the validity of a configuration file like syntax or if referenced file paths are present on the file system:
$ apache/bin/httpd -t
Syntax OK
Alternatively, its also possible to check the syntax with apachectl configtest.

Some excerpts

Some excerpts from my httpd.conf file that I wish I could remember…
Listen 80

ServerRoot "C:/Users/rene/xampp/apache"
…
DocumentRoot "C:/Users/rene/htdocs"

<Directory "C:/Users/rene/htdocs">

  #
  # Options: either
  #  - None      , or
  #  - All       , or
  #  - any combination of
  #    - Indexes
  #    - Includes
  #    - FollowSymLinks
  #    - SymLinksifOwnerMatch
  #    - ExecCGI
  #    - MultiViews            (Not included with All)
  #

    Options Indexes FollowSymLinks Includes ExecCGI

  #
  # AllowOverride controls the set of directives that
  # can be placed in a .htaccess file.
  #
    AllowOverride All

  #
  # Who is allowed to access this server
  #
    Require all granted
</Directory>


<IfModule dir_module>
  #
  # Which file is served if URL is a directory:
  #
    DirectoryIndex index.php index.html index.htm
</IfModule>


<Files ".ht*">
  #
  # Prevent .htaccess and .htpasswd
  # from being served
  #
    Require all denied
</Files>

#
#  Allow to execute <?php … ?> snippets in
#  HTML documents.
#
AddType application/x-httpd-php .html .htm  

See also

XAMPPs httpd.conf file.

Index