Purpose of Debian "sites-available" and "sites-enabled" directories?
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?
sites-available contains the apache config files for each of your sites. For example:
<VirtualHost *:80>
ServerName site.mysite.com
ServerAdmin [email protected]
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.
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
).
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.