55

Can anyone tell me—in a nutshell—what the purpose of these two directories are in Debian?

/etc/apache2/sites-enabled
/etc/apache2/sites-available

I notice that diffing sites-available/000-default and sites-enabled/default shows they are identical.

What gives?

migrated from stackoverflow.com Nov 11 '09 at 5:09

This question came from our site for professional and enthusiast programmers.

61

sites-available contains the apache config files for each of your sites. For example:

<VirtualHost *:80>
  ServerName site.mysite.com
  ServerAdmin my@email.com

  DirectoryIndex index.php
  DocumentRoot /home/user/public_html/site.mysite.com/public

  LogLevel warn
  ErrorLog /home/user/public_html/site.mysite.com/logs/error.log
  CustomLog /home/user/public_html/site.mysite.com/logs/access.log combined
</VirtualHost>

When you want to add a new site (for example, site.mysite.com), you add it here, and use:

a2ensite site.mysite.com

To enable the site. Once the site is enabled, a symlink to the config file is placed in the sites-enabled directory, indicating that the site is enabled.

  • 12
    If you want to disable a site, you would run a2dissite site.mysite.com – Jason Leveille Nov 11 '09 at 1:43
  • 2
    a2ensite and a2dissite are located in /usr/sbin which is currently not included in the default user path so tab completion won't work. When typing sudo a2 and pressing the tab key however you will be offered both a2ensite and a2dissite. – Stefan Schmidt Jun 29 '13 at 19:39
19

More important than the mechanics of the system is the rationale...

Debian provides the two separate directories so that if you're automatically managing your Apache configs, you can just have all of the vhosts drop into sites-available on all your machines, and then individual vhosts can be enabled on the server that will actually serve them. It also means you can near-instantaneously disable a site if it's causing problems (a2dissite example.com; /etc/init.d/apache2 reload).

  • 1
    This one is true answer for original question. – silpol Nov 11 '14 at 10:04
4

To add to those above, the file in sites-enabled is a symlink to the sites-available file:

ls -l /etc/apache2/sites-enabled/

It’s not just the same content, it’s the same actual file!

1

Important information:

You should edit files only in sites-available directory.

Do never edit files inside the sites-enabled directory, otherwise you can have problems if your editor runs out of memory or, for any reason, it receives a SIGHUP or SIGTERM.

For example: if you are using nano to edit the file sites-enabled/default and it runs out of memory or, for any reason, it receives a SIGHUP or SIGTERM, then nano will create an emergency file called default.save, inside the sites-enabled directory. So, there will be an extra file inside the sites-enabled directory. That will prevent Apache or NGINX to start. If your site was working, it will not be anymore. You will have a hard time until you find out, in the logs, something related to the default.save file and, then, remove it.

In the example above, if you were editing the file inside the sites-available directory, nothing bad would have happened. The file sites-available/default.save would have been created, but it wouldn't do any harm inside the sites-available directory.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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