Purpose of Debian "sites-available" and "sites-enabled" directories?
Solution 1:
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.
Solution 2:
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
).
Solution 3:
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.
Solution 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!