Ubuntu Hardy - Apache config layout

Ubuntu Hardy Heron uses a different Apache layout than you may have encountered if you have used Apache with non-Debian based Operating Systems.

The differences are not huge and, indeed, help in configuring and deploying websites.


Assuming you have used aptitude to install Apache (see the Ubuntu Hardy Apache and PHP install article), move into the config folder and have a look:

cd /etc/apache2

You will see this:

Apache Configuration Directory

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


Inside sites-available will be files containing the configurations for each site you want to serve - these are known as vhosts or virtual hosts.

Have a look now and see that there is one site (default) available:

ls sites-available/

The apache install has a 'default' vhost available - when we navigated to the Slice IP and got the 'It works!" message, it was this default file that told Apache what to do and where the files were located.

We'll look at vhosts in more detail and create our own in a later article.

Do note that a file in sites-available does not mean they are active. They are simply available for serving if you enable them. Which brings us to...


This folder contains symlinks to the sites you actually want to serve.

For example, you could have 2 vhosts configured and ready to use in the sites-available folder, but only one of them enabled. Only the one symlinked from the sites-enabled folder would be served.

Have a look at the default contents:

ls -l sites-enabled
lrwxrwxrwx 1 root root 36 Apr 28 10:40 000-default -> /etc/apache2/sites-available/default

This means that the 'default' site has been enabled - the symlink named '000-default' links to the 'default' file in the sites-available folder.

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.


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.

Just as with the vhosts files, any modules that we want to use must be enabled.....


This folder contains symlinks to the modules that we want enabled. 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 all our sites are enabled.

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

They are a2dissite, a2ensite, a2dismod and a2enmod.


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:

sudo /etc/init.d/apache2 reload

When you now visit your Slice IP, instead of the nice 'It Works!' page, you will get a 404 Not Found message.

Note the main vhosts file in sites-available is still there - all the a2dissite command did was remove the symlink in the sites-enabled folder.


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:

sudo /etc/init.d/apache2 reload

Visit your Slice IP - the default 'It works!' page is being served again.


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.


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.


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

The next couple of articles will discuss the main apache2.conf file and look at what changes can be made to optimise the install.


Article Comments:

Eric Fields commented Wed Aug 27 00:26:09 UTC 2008:

Following the tuts and loving it.

Didn't have the a2* commands by default and had to dive into IRC to get some help. For my user account (non-root), had to add the /usr/sbin path to .profile.

Hope it helps somebody.

vinhboy commented Thu Sep 11 18:24:55 UTC 2008:

I think my favorite command with this tutorial is

sudo a2enmod rewrite

since most apps uses rewrite... am I doing it right??

Chris commented Tue Oct 14 07:08:47 UTC 2008:

Total noob question. I have PHP/MySQL installed but I'm missing very basic now. I connected to my Slice through SFTP and all I see is:

.bash_history .bash_logout ... .rnd

I would like to upload my Joomla site to /var/www where the default site is linking to. How do I "see" /var/www and upload into that directory? I'm using FileZilla as SFTP client.

Chris commented Tue Oct 14 07:25:10 UTC 2008:

Aha, nevermind. Realized that upon connecting, you are automatically directed to your home user directory: /home/<username>

Solution is to go out to the main root to find /var/www

julien commented Mon Nov 03 19:16:29 UTC 2008:

i don't know if it's normal, but when i did the sudo a2dismod php5, it told me "Module php5 does not exist!". I corrected this by manually installing the libphp5.so module from the package i downloaded with aptitude.

SreeVidhya commented Mon Dec 22 11:33:02 UTC 2008:

I have PHP/MySQL installed.I would like to upload my Joomla site in slicehost.what steps to be take.

Steve commented Thu Feb 25 11:05:49 UTC 2010:

If you don't know how to configure apache and upload a site, then please don't install Joomla yet. Joomla requires a great deal of configuration on your part if you want it to perform well and securely in a Slicehost environment. Please see my post at http://forum.slicehost.com/comments.php?DiscussionID=2343 for some guidelines.

Danny commented Wed Apr 21 20:14:55 UTC 2010:

typo: told Apache what to do and where the files where located

Truly appreciate the work put into these Slicehost tutorials. Brilliant!

アンティーク 非常にダイナミック commented Wed Jul 16 06:02:43 UTC 2014:

I want to to thank you for this excellent read!! I absolutely loved every bit of it. I have you bookmarked to look at new stuff you post…

Stop by my website - アンティーク 非常にダイナミック

Want to comment?

(not made public)


(use plain text or Markdown syntax)