Debian Etch - Apache config layout

Installation of Apache on Debian is relatively easy. Where some confusion arises is the layout Debian uses for configuration of Apache (and Apache configuration in general).

However, the Debian layout is not massively different from a 'classic' layout but enough to warrant an introduction.


Looksee

Assuming you have used aptitude to install Apache, move into the config folder and have a look at what's there:

cd /etc/apache2
ls

You will see this: Apache Configuration Directory

The folders are highlighted in blue. Let's look at those first:

sites-available

Inside here will be files containing the configurations for each site you want to serve. Have a look now and see that there is one site (default) available. Although we'll look in detail later at the sites configuration files, you can take a look now:

nano sites-available/default

As I say, we'll look in more detail at the actual configuration later.

Do note that a file in sites-available does not mean they are active. You need to enable them first. Which brings us to...

sites-enabled

These are symlinks to whichever sites you want to enable.

So if you had 5 sites configured and available, nothing would happen until you enabled them to be served.

Have a look at the default contents:

ls -l sites-enabled

You will see this:

Apache sites-enabled

Apart from the horrible colour format of the symlink, you will see it is named 000-default and points to an 'available' site at /etc/apache2/sites-available/default.

This means that the 'default' site has been enabled. Without the symlink in this folder it would remain available (in the sites-available folder) but not active.

The other thing to note is the naming. It's possible for a domain to point to your Slice IP but have no site configuration file. In these cases, the first enabled site (alphabetically) will be displayed i.e. 000-default's config will be used.

mods-available

Well, I guess you get the idea already but this folder holds the modules that are available to be loaded.

Have a look:

ls mods-available

A fair list is available from our base install but remember that they are not all enabled, merely available for use. Which brings us to...

mods-enabled

A list of symlinks to the modules you want to enable. Have a look and compare it to the list of modules available:

ls mods-enabled

This list is a lot shorter than the list of available modules (meaning not all the available modules are enabled) and includes php5.conf - which is handy as we installed PHP5 earlier.

a2en and a2dis

Being a good sysadmin, we like to get stuck in and create our vhosts and now we know how the symlinks work we could go ahead and 'ln -s' until we are happy.

However, there are some commands that make this process much easier.

They are a2enmod, a2ensite, a2dismod and a2dissite.

a2dissite

This will delete the symlink to a site you have previously enabled.

For example, let's disable the default site:

sudo a2dissite default

The symlink in sites-enabled has been deleted and the output is as follows:

Site default disabled; run /etc/init.d/apache2 reload to fully disable.

Reload Apache as indicated to ensure the site is fully disabled. You can test this by visiting your Slice IP address. Instead of the nice 'It Works!' page, you will now get a 404 Not Found message.

a2ensite

Let's enable the default site again:

sudo a2ensite default

The output:

Site default installed; run /etc/init.d/apache2 reload to enable.

Reload Apache and visit your Slice IP - the default is now being served again.

a2dismod

In the same way as just shown, a2dismod will disable any modules you have previously enabled:

sudo a2dismod php5

The output:

Module php5 disabled; run /etc/init.d/apache2 force-reload to fully disable.

That will disable the php5 module and if you look in the mods-enabled folder, you will see that the symlinks php5.conf and php5.load have been deleted.

a2enmod

I reckon you've got it now, but to enable the php5 module simply enter:

sudo a2enmod php5

The output:

Module php5 installed; run /etc/init.d/apache2 force-reload to enable.

And a quick check will show that indeed, the php5.conf and php5.load symlinks are back in the mods-enabled folder.

Done

Don't forget to reload Apache after each site or module change.

We'll talk about site configurations and the main httpd.conf file in the next articles.

PickledOnion.

Article Comments:

Elda commented Wed Oct 03 14:45:54 UTC 2007:

This is best explanation I have seen. I am novice and would to see the continuation of this article(s). Please can you point me to the rest... Thanks a lot!!

PickledOnion commented Wed Oct 03 14:51:59 UTC 2007:

Hi Elda,

Thanks for the kind words :)

I add more articles each week (usually on a daily basis) so keep on checking back for more.

There are some more in the Debian section and even more in the Apache section (see the Site Menu).

Feel free to add any requests you may have if you have something specific that may help.

PickledOnion.

Raul commented Sun Nov 11 09:42:17 UTC 2007:

I have been reading some of your articles and I would like to thank you for making things clear for me, you know I am just starting with apache.

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)