32

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)?

3 Answers 3

44

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.

4
  • Great summary! Much more clear and concise than the one I was working on. +1. Dec 26, 2010 at 18:44
  • 3
    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, 2010 at 22:04
  • +1. When you need to maintain these configurations go to 'sites-enabled' instead of 'sites-available' and access them directly from there. This way you will always be able to determine and access the currently used site configurations.
    – Ross
    Feb 4, 2015 at 22:50
  • @Ross comment is valid when you are copying files from sites-available to sites-enabled; no difference instead when symlinking_ files (what a2ensite` does). Nov 15, 2023 at 0:39
10

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.

-2

The Apache in linux can be installed by two types . one is by apt-get and other download tar file and extract .... Thus in apt-get process sites are served out from /etc/apache2/sites-enabled folder as each site serving to outside world is configured in these folder by .conf files example 000-default.conf is a default site enabled to show apache works .

thus by creating any .conf file in sites-enabled and directing it to location of content ..thus site is served .

So in order to add a new static site a new .conf file has to be created in sites-enabled folder with whatso ever name example example.conf . and has to add the below lines in it

ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined

Where as , *:80 indicates "open to world through port 80" DocumentRoot /var/www/html indicates "path of site contents "

1
  • This wrong and misleading. You create your files in sites-available so that the tools (recommended) such as a2ensite can work. Typically you symlink these conf files using a2ensite into sites-enabled. apt-get has nothing whatsoever to do with configuring your sites.
    – RichieHH
    Sep 2, 2018 at 11:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .