It’s been over 10 years now since I started using Debian. I have got used to its organisation so much that I tear my hair often when I have to work with other distros. But I have to agree that it’s the same with guys from the other side of the fence. Hence, I’m putting my understanding of how Debian Apache HTTPD or in package terms “apache2”, is organised. This should be handy if you have to configure Debian/Ubuntu and have never used it before.
“apache2” is a meta-package on Debian, or in other words, a dummy package that collates all other related packages to form a full package. It’s an easy way to group from the distribution provider’s point of view for maintenance and upgrades.
Below is the package structure for out-of-box installation
Apache Configuration Directory - /etc/apache2
Apache Root Directory - /var/www
If you have used Apache before, the Root directory is fairly straightforward to understand. The confusion is more to do with the configuration directory. First of all, in RedHat-based systems, Apache configurations are stored under /etc/httpd, and Debian is a bit different, as you can see from the above.
Let’s look at the actual folder structures inside /etc/apache2. Below is a snapshot from my local Apache installation.
-rw-r--r-- 1 root root 7994 Sep 29 2011 apache2.conf
-rw-r--r-- 1 root root 1169 Sep 29 2011 envvars
-rw-r--r-- 1 root root 158 Aug 27 08:20 httpd.conf
-rw-r--r-- 1 root root 31063 Sep 29 2011 magic
-rw-r--r-- 1 root root 750 Sep 29 2011 ports.conf
drwxr-xr-x 2 root root 4096 Apr 16 21:09 conf.d
drwxr-xr-x 2 root root 12288 Aug 27 08:25 mods-available
drwxr-xr-x 2 root root 4096 Aug 27 08:25 mods-enabled
drwxr-xr-x 2 root root 4096 Aug 25 23:05 sites-available
drwxr-xr-x 2 root root 4096 Nov 2 2011 sites-enabled
Here is a brief about what each file or folder does
apaceh2.conf - This is the main configuration file that drives Apache on Debian-based machines. If you look inside, it’s fairly straightforward to understand what it’s doing. This is the file you should be modifying if all you have to change are some global settings. Having said that, if you follow the Debian way of doing things, you will be changing sub-config files rather than this file. Read on, you will understand what I’m saying.
apache2.conf is very specific to Debian, and you won’t find it on RedHat machines.
envvars - As the name suggests, this file holds environment variables required for running Apache. This file is internally referenced when Apache starts up.
httpd.conf - This file might not even exist. If you lose your way, and as a last resort, create this file and put your configurations there. This file will be referenced if it exists. This is the same file that many distros refer to as the main Apache configuration file. This file can contain everything, assuming you want to break away from the Debian way of doing things.
magic - Holds supported MIME types. This is the file you have to tinker with if you have to add or remove supported MIME types.
ports.conf - As in the name, this is the file to go to if you have to change Apache’s default ports. This file is referenced inside the apache2.conf
mods-available - This directory holds the .load file for each Apache module that exists on the system. If you look inside any one of them, there will be a one-liner that points to the static object which Apache has to load. This folder also contains a .conf file, a configuration file necessary to configure the module.
If you have to configure the default setting of a module, say “status”. Then search for a conf file in this folder with the name “status.conf” and make the changes in that file. The contents of this folder are parsed during Apache startup. This folder is referenced inside apache2.conf
mods-enabled - This directory holds a subset of files from mods-available. These are the modules that are currently loaded or will be loaded when Apache starts. If you inspect the files under the folder, you will find them symlinked to mods-available.
You can either create a symlink using the “ln” command from mods-available to mods-enabled or use one of the Apache helper scripts that come with Debian. Read on to find out those helper commands.
sites-available - As in the name, this directory holds all the sites/virtual hosts Apache knows about. Any changes you have to make to a site should be made here.
It’s similar in functionality to mods-available. These are all the sites on the system, but not necessarily the sites that are currently live. There is one file per virtual host in this folder, and that’s a rule of thumb; if you can keep it that way, you will be making your life easier down the line.
sites-enabled - Lists all sites that are currently live or will be live once Apache starts up. All the files are symlinks to files in sites-available.
Below is a list of helper scripts that come with the default Debian installation -
a2ensite
- Script that would create a symlink from sites-available to sites-enabled
a2dissite
- Script to remove the symlink created by a2ensite
command.
a2enmod
- Creates a symlink from mods-available to mods-enabled.
a2dismod
- Removes the symlinks from mods-enabled, if it exists.
apache2ctl
- Apache control command, use it in place of where you used “httpd” on RedHat.
Hope this write-up would help someone looking for a quick walkthrough on Apache structure on Debian/Ubuntu. If you find it helpful or if you find anything that’s not correct, drop me a line.