Apache in Debian based systems | Day in my life

August 27, 2012

Apache in Debian based systems

Its 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 its the same with guys from other side of 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. Its easy way to group from the distribution provider point of view for maintenance and upgrades.

Below is package structure for out-of-box installation
Apache Configuration Directory - /etc/apache2
Apache Root Directory - /var/www

If you have used Apache before, Root directory is fairly straight forward to understand. The confusion is more to do with configuration directory. First of all in RedHat based system Apache configurations are stored under /etc/httpd and Debian is bit different, as you can see from the above.

Lets 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, its fairly straight forward to understand whats its doing. This is the file you should be modifying if at all you have to change some global settings. Having said that, if you follow 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 wont find it on RedHat machines.

envvars - As name suggests, this file hold environment variables required for running Apache. This file is internally referenced when Apache starts up.

httpd.conf - This file might not even exists. If you loose your way and as a last fall back create this file and put your configurations there. This file will be referenced if it existis. 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 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 name, this is the file to go to if you have to change Apache default ports. This file is referenced inside apache2.conf

mods-available - This directory holds .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 would point to the static object which apache has to load. This folder also contains .conf file, an configuration file necessary to configure the module.

If you have to configure default setting of a module say “status”. Then search for a conf file in this folder with name “status.conf” and make the changes in that file. The contents from 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 “ln” command form 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 host Apache knows about. Any changes you have to make for a site should be made here.

Its similar in functionality as mods-available. These are all the site on the system but not necessary the sites that are currently live. There is one file per virtual host in this folder and thats a rule of thumb and 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 list of helper scripts that come with 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 exits.
apache2ctl - Apache control command, use it in place where you used “httpd” on RedHat.

Hope this writeup 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.

© Nataraj Basappa 2021