Let's take a look at where apache's config files wind up when installed with the RHEL 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 yum, you will find the root of apache's config directory at:
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:
You should see something like this as the output:
conf conf.d 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. Well, 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.
This directory holds the main apache configuration. Inside you should find three items: httpd.conf, magic, and custom.
This is the first configuration file apache will read, and 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.
Despite its inviting name, the "magic" file is a difficult file to read through. The magic file stores information about MIME types. MIME types are essentially identifiers a web server and web client will use 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.
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:
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.
The conf.d directory is meant to hold module config files, according to the "README" file you'll find therein.
In the httpd.conf file you'll find the Include directive that reads the files in this directory into the configuration right after a bunch of LoadModule directives:
The placement of that Include directive is fairly important. It means that these config files will be read right after modules are loaded, and before any other settings are parsed. That means that you probably will want to only use the conf.d directory for those module configs, and put any custom configs in that "custom" directory you made earlier.
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.
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.
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.
Over in /etc/sysconfig
One more configuration file to be aware of is unique to distributions that use the Red Hat sysconfig directory structure to store many system settings:
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. 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.
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