Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've been trying to follow a few basic tutorials explaining how to get Apache up and running (on ubuntu, running on Amazon). I've mostly come up blank, because all the tutorials told me to configure httpd.conf (to add DocumentRoot, etc.).

I've now stumbled across one tutorial that told me to add site configurations to the sites-available directory (under /etc/apache), and then symlink to it from sites-enabled. Configuring this way seems to work.

But now I'm confused - how am I supposed to configure Apache? Most tutorials still seem to say that I should be using httpd.conf. Which one should I be using? What's the difference? Why are all the tutorials "wrong" (if they are)?

share|improve this question
add comment

2 Answers

up vote 14 down vote accepted

The sites-available method is generally considered the "Debian Way":

  • "main" config in /etc/apache2/apache2.conf
  • "user" config in /etc/apache2/httpd.conf
  • vhosts in /etc/apache2/sites-available files (one per file, typically)
    • you might want to number them, e.g. 00-domain.com, 01-otherdomain.com
  • ports (Listen directives) in /etc/apache2/ports.conf
  • mods in /etc/apache2/mods-available

You can manipulate these with symlinks or with the a2 series of commands:

a2ensite/a2dissite <site_config_filename>
a2enmod/a2dismod <module_name>

Depending on personal preference, you can restart Apache using apachectl, /etc/init.d/apache2 (start|stop|reload|restart), or service apache2 (start|stop|reload|restart)

An example where you would use httpd.conf instead of a vhost entry would be for a global redirect or rewrite rule, for example. Other tidbits -- generally, you should leave apache2.conf alone, and make sure you set up a consistent naming scheme for vhosts in the sites-available directory.

share|improve this answer
    
Great summary! Much more clear and concise than the one I was working on. +1. –  Steven Monday Dec 26 '10 at 18:44
1  
Sites available provides good modularization of the configuration. It enables you to focus on a single site's configuration easily. It also makes it much easier to compare sites on a server or to move or replicate a site between servers. –  BillThor Dec 26 '10 at 22:04
    
Thanks Sam, nice explanation! –  Ida Ebkes Apr 17 '13 at 10:19
add comment

The location and organisation of the configuration files is configurable and can change between major releases or between distributions.

The Apache Wiki has a handy guide to the names and locations of the configuration files.

Because the config files can contain include directives, parts of the configuration can be separated out into smaller files. Since a standard Apache configuration file contains many comments and lots of standard items, it makes some sense to separate out the parts you are most likely to change.

The name of the main configuration file can be changed at compilation time and in recent releases it has changed from httpd.conf to apache2.conf

Over the years there has been some evolution in the organisation of the included configuration files too.

For example, I installed Apache2 on a Ubuntu-based system using apt-get install apache2 - here's the included files

/etc/apache2$ ls
apache2.conf  envvars     mods-available  ports.conf       sites-enabled
conf.d        httpd.conf  mods-enabled    sites-available

/etc/apache2$ grep ^Include apache2.conf
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
Include /etc/apache2/httpd.conf
Include /etc/apache2/ports.conf
Include /etc/apache2/conf.d/
Include /etc/apache2/sites-enabled/ 

/etc/apache2$ ls -l sites-enabled
total 0
lrwxrwxrwx 1 root root 26 Dec 26 12:30 000-default -> ../sites-available/default

So the few configuration settings you are likely to be most interested in are now in /etc/apache2/sites-available/default.

I can see that this is consistent with the Ubuntu documentation for Apache which I recommend you read first. If you have other documentation for older versions of Apache (or other distributions) you can adapt that information to suit the way things are organised in Ubuntu.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.