Understanding the Role of sites-available and sites-enabled in Apache2 on Debian-Based Systems


2 views

In Debian-based systems, Apache2 uses a logical separation between available configurations and active configurations through two directories:

/etc/apache2/sites-available/  # Stores all possible site configurations
/etc/apache2/sites-enabled/     # Contains symlinks to enabled configurations

The sites-available directory serves as a repository for all virtual host configurations, whether active or not. The sites-enabled directory contains symbolic links to configuration files that should be active.

When Apache starts, it only reads configurations from sites-enabled. The standard practice is to create symlinks from sites-enabled to sites-available:

# Enable a site
sudo a2ensite example.com.conf

# Disable a site  
sudo a2dissite example.com.conf

Here's what happens when you create a new virtual host:

# 1. Create config in sites-available
sudo nano /etc/apache2/sites-available/example.com.conf

# 2. Enable it
sudo a2ensite example.com.conf

# 3. Verify symlink
ls -l /etc/apache2/sites-enabled/example.com.conf
# Should show: example.com.conf -> ../sites-available/example.com.conf

This architecture provides several benefits:

  • Easy to disable sites without deleting configuration files
  • Clean organization of all possible configurations
  • Simple backup of all potential configurations
  • Standardized across Debian-based systems

1. Editing the symlink: Always edit files in sites-available, not sites-enabled.

2. Missing symlinks: If Apache isn't loading your config, verify the symlink exists.

3. File naming: Ensure your config files end with .conf for proper recognition.


In Debian-based systems with Apache2, you'll find this structure:
/etc/apache2/
├── sites-available/
│ ├── 000-default.conf
│ ├── example.com.conf
├── sites-enabled/
│ ├── 000-default.conf -> ../sites-available/000-default.conf
│ ├── example.com.conf -> ../sites-available/example.com.conf

The key differences:

sites-available/ - Stores all possible virtual host configurations
sites-enabled/ - Contains symlinks to active configurations

Apache only reads files from sites-enabled. The identical content you observed occurs because:

ls -l /etc/apache2/sites-enabled

Shows they're symbolic links pointing back to sites-available.

Enable a site:
sudo a2ensite example.com.conf

Disable a site:
sudo a2dissite example.com.conf

Here's a sample configuration in sites-available:


<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Advantages:
- Easy to disable sites without deleting configs
- Clean separation between available and active configs
- Atomic changes (modify in available, then enable)
- Supports version control of all possible configs

Create custom site templates:

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/template.conf

Then modify as needed for new sites.

Common issues:
- Broken symlinks in sites-enabled
- Syntax errors in available configs
- Permission problems
- Missing a2ensite/a2dissite commands

Check with:
apache2ctl configtest