Apache configuration files on Arch

Let's take a look at where apache's config files wind up when installed with the Arch package manager.


The apache config directory

Let's take a look at where apache gets its settings from. Note that when we talk about a "config" we mean "configuration" or "configuration setting", depending on the context. Think of the shorthand version as hip hacker slang.

If you went through the first article in this series to install apache via pacman you will find the root of apache's config directory at:

/etc/httpd/

If you compiled apache from source you probably won't see it there, you rebel you. The configuration directory will be wherever you told it to be during your install. Maybe poke around in /usr/local/.

If you take a look inside that directory:

ls /etc/httpd/

You should see something like this as the output:

build  conf  logs  modules  run

The Include directive

Before we dive into what each file in this directory is for let's talk about my favorite apache directive ever: Include.

While it's possible to cram every apache setting into the main config file, it can be a bit awkward having to open one huge file and navigate through it every time you want to make a change. That's why the apache team thoughtfully provided a way to add more config files to your installation.

The "Include" directive tells apache to read another file and parse it for configuration options. More than that, it can also point to a directory and tell apache to read all or some of the files in that directory. In short, it's pretty darned nifty if you're trying to reduce the headaches that come with editing one gargantuan config file every time you need to add a site.

Why am I telling you about this directive now, instead of waiting for the more detailed configuration articles? Well, for one thing, because we already used it once. And for another, the main apache config file has an Include by default to a directory that holds all the module config files. That should give you an idea of how the additional config files are used and how you can set up your own includes down the line.

With the stage set, let's look at the other things you'll find in the apache config directory.

conf

This directory holds the main apache configuration. Inside you should find five items: httpd.conf, extra, magic, mime.types, and custom.

httpd.conf

/etc/httpd/conf/httpd.conf

This is the first configuration file apache will read. It contains most of the settings for apache by default.

The file is pretty well-commented, so you can look through the file contents (with "cat" or "more" or "less", your preference) and get some idea of what the default settings look like and how you can change them. We'll go into the most important ones in a later article so for now it's okay to just skim.

When you look through httpd.conf note the Include directives you'll find (including, presumably, the one we added when we installed apache.

extra

/etc/httpd/conf/extra

The "extra" directory contains, well, extra config files. Arch uses this directory to break up the apache configuration into smaller, more manageable files, through the magic of Include.

For example, the "httpd-vhosts.conf" file contains the configuration for the default virtual host, while "httpd-mpm.conf" contains configuration directives related to the MPMs.

We'll talk about what virtual hosts and MPMs are later. For now just know that the Include directives pointing to the files in the "extra" directory are at the end of "httpd.conf", and that not all are used by default. If you want to change the settings in one of these files check to make sure its Include statement in the main httpd.conf file is uncommented.

magic

/etc/httpd/conf/magic

Despite its inviting name the "magic" file is a difficult one to read through. It's used by apache to determine the MIME types of files based on their headers.

MIME types are identifiers used by web servers and web clients to indicate that a file is of a particular type. For example, "application/pdf" is the MIME type for a PDF file.

If that doesn't make a lot of sense to you don't worry about it. Just know that this isn't a file you're likely to want to change unless you understand MIME types and the proper format of the entries in this file.

mime.types

/etc/httpd/conf/mime.types

Like the "magic" file, the "mime.types" file is used to determine the MIME type of a file. The difference is that mime.types uses the extension on a file to determine its MIME type instead of looking at the file's headers.

Also like the "magic" file, you usually won't want to make changes to the "mime.types" file.

Your custom configs

Now we come back to that Include directive. If you didn't create a directory to hold your custom configs back when you set the ServerName, make the directory now:

sudo mkdir /etc/httpd/conf/custom

And if you haven't already, add an Include directive to the end of the httpd.conf file:

Include /etc/httpd/conf/custom/*.conf

When adding a directive to apache that doesn't belong somewhere else consider putting it in a file in "custom" instead of editing the main config file. Using your custom directory to hold changes makes it easier to isolate a recent configuration change (by checking modification dates), lets you find directives you've added quicker, and reduces the risk that you could make a bad edit in the main config file.

Bear in mind that the way we set it up the Include directive will only grab files from conf/custom that end in a ".conf" extension. That means you can change the name of a config file to disable it easily without deleting it entirely.

logs

/etc/httpd/logs

The "logs" item in the apache directory is a symlink to where apache stores its main log files, /var/log/httpd. It's included in this directory as a convenience, so the config file can refer to that local "logs" directory instead of needing to contain the absolute path to the logs directory.

modules

/etc/httpd/modules

The modules item is also a symlink, this time to /usr/lib/httpd/modules. Those are the libraries that apache reads as modules to add features like server-side includes and PHP support. This is also a symlink created as a configuration convenience.

run

/etc/httpd/run

Yet another symlink, this one points to /var/run/httpd. This directory should generally hold only one file, and it should only be there when apache is running. That file, "httpd.pid", stores the main process ID for apache. Don't try to change it.

build

/etc/httpd/build

The other item (and symlink) in /etc/httpd points to "/usr/lib/httpd/build". The files in the build directory include the configuration file that was used to build apache and other files that would be used to pass instructions to a compiler. You only need to look into these files if you want to recompile apache so that it's similar to the version you just installed, or if you compile a module that wants to model its build after the current apache install.

Over in /etc/conf.d/apache

One more configuration file unique to Arch is in the /etc/conf.d directory used to store some distribution-specific configurations:

/etc/conf.d/apache

It's a short file, but we really just want to look at the first setting listed:

# The default processing model (MPM) is the process-based
# 'prefork' model. A thread-based model, 'worker', is also
# available, but does not work with some modules (such as PHP).
# The service must be stopped before changing this variable.
#
#HTTPD=/usr/sbin/httpd.worker

It's commented out right now, but you can use the HTTPD setting in this file to control what MPM apache will use when it launches (by changing the name of the binary it launches, like "httpd.worker" or "httpd.itk"). The comment in the file does a good job of describing why you might want to change the MPM, and why you might not. For now, let's not. Especially since we'll be going into important questions like "What's an MPM?" in the next article in this series.

Summary

That should cover the files that can be found in apache's configuration directory after a package install, and what settings you can generally expect to find where. Remember that when you alter apache's configuration you'll need to reload or restart the web server before the change will take effect.

In the next article we'll look at apache's MPM options and how you may want to change them to account for your server's available memory.

  • -- Jered
Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)