Beginner Fundamentals

Directives and Contexts

A directive is a single configuration instruction that tells Apache how to behave. The configuration files are simply lists of directives.

Basic Syntax

A directive has a name followed by one or more values, one per line:

ServerName example.com
Listen 80
DocumentRoot /var/www/html

Lines starting with # are comments and are ignored.

Container Directives

Some directives group others inside a block. They use an XML-like opening and closing tag:

<Directory /var/www/html>
    Options Indexes FollowSymLinks
    AllowOverride None
</Directory>

Contexts

Each directive is only valid in certain places, called contexts:

  • Server config: the main file, outside any block (global settings).
  • Virtual host: inside <VirtualHost>.
  • Directory: inside <Directory>, <Location>, or a .htaccess file.

If you put a directive in the wrong context, Apache reports an error on reload.

Including More Files

The Include directive pulls in extra configuration so you can keep files organized:

Include conf-available/*.conf

Knowing directives and contexts is the foundation for everything that follows.