VMware ESXi and vSphere Cluster Management

Apache mods-enabled Directory: Enabling and Disabling Modules

Learn how Debian and Ubuntu Apache use mods-available and mods-enabled, including a2enmod, a2dismod, symbolic links, validation, reloads, and troubleshooting.

On Debian- and Ubuntu-based systems, Apache HTTP Server uses a structured configuration layout. The /etc/apache2/mods-enabled directory contains the Apache module definitions selected for use by the server.

An Apache module is an extension that adds capabilities such as URL rewriting, TLS, authentication, proxying, compression, or custom HTTP headers. Understanding the difference between an installed module and an enabled module helps you change Apache safely.

What /etc/apache2/mods-enabled Means

/etc/apache2/mods-enabled contains the module configuration files that Apache is intended to load. On Debian and Ubuntu, these entries are normally symbolic links to files stored in /etc/apache2/mods-available.

Apache reads the enabled module definitions when it starts or when its configuration is reloaded. Creating or removing a link changes the filesystem configuration, but it does not change an already running Apache process until the service is reloaded or restarted.

A symbolic link is a filesystem reference that points to another file. In this layout, a link in mods-enabled points to a module file in mods-available.

mods-available and mods-enabled

The two directories represent separate states:

  • /etc/apache2/mods-available contains module configuration files installed on the system and available for activation.
  • /etc/apache2/mods-enabled contains links for the module files selected as active.

Availability does not mean activation. A package can install a module binary and its configuration into the system while leaving the module disabled. Conversely, disabling a module usually removes only its links from mods-enabled; the package and source files in mods-available remain installed.

The directory relationship can be summarized as follows:

  • Available definition: /etc/apache2/mods-available/rewrite.load
  • Enabled reference: /etc/apache2/mods-enabled/rewrite.load
  • Result: Apache can read the enabled definition during startup or reload.

Module Directory Roles

  • /etc/apache2/mods-available: Contains installed module load files and optional configuration files. These files define what can be enabled.
  • /etc/apache2/mods-enabled: Contains symbolic links to selected files in mods-available. These links determine which module definitions Apache reads.

.load and .conf Files

Module definitions commonly use two file types:

  • A .load file usually contains a LoadModule directive. This directive tells Apache to load a module binary.
  • A .conf file contains optional module-specific settings, such as directives that control behavior after the module has been loaded.

Not every module has both files. A module may have only a .load file, or it may have a matching pair such as rewrite.load and rewrite.conf. When a module has both, the helper command normally enables the appropriate links together.

Installing a Module Versus Enabling It

Installing a module means placing its package, binary, and/or available configuration files on the system. Enabling a module means selecting it for Apache by creating the appropriate links under mods-enabled.

These operations are related but not identical. A module can be installed and inactive until it is enabled. Package-maintainer behavior varies: some packages enable a module automatically, while others leave activation to the administrator.

For example, a package installation might provide files in mods-available, after which you still run a2enmod. Always check the package documentation and the local directory contents rather than assuming installation activated the module.

Enabling a Module with a2enmod

a2enmod is the Debian and Ubuntu helper command for enabling an available Apache module. It creates the appropriate symbolic links under /etc/apache2/mods-enabled. Elevated privileges are normally required.

sudo a2enmod rewrite

After the command completes, validate the configuration before applying it:

sudo apache2ctl configtest
sudo systemctl reload apache2

A successful configuration test normally prints Syntax OK. Reloading applies the new configuration without necessarily stopping the service completely.

Worked Example: Enabling mod_rewrite

mod_rewrite is commonly used for URL transformations and redirects. On many Debian and Ubuntu installations it is already supplied by the Apache package, so no separate package installation is needed.

  1. Check whether matching files exist:
ls -l /etc/apache2/mods-available/rewrite.*
  1. Enable the module:
sudo a2enmod rewrite
  1. Inspect the resulting enabled entries:
ls -l /etc/apache2/mods-enabled/ | grep rewrite
  1. Test the configuration:
sudo apache2ctl configtest
  1. Reload Apache:
sudo systemctl reload apache2
  1. Confirm that Apache reports the module as loaded:
sudo apache2ctl -M | grep rewrite

The loaded-module output should include a name similar to rewrite_module.

Disabling a Module with a2dismod

a2dismod disables a named Apache module. It removes the corresponding symbolic links from mods-enabled while leaving the module files in mods-available and generally leaving the installed package untouched.

sudo a2dismod rewrite
sudo apache2ctl configtest
sudo systemctl reload apache2

Do not disable a core dependency or a module required by an active virtual host without checking its dependencies first. A disabled module can cause Apache to fail validation, prevent a reload, or change site behavior. For example, a virtual host or .htaccess file may use directives supplied by the module.

Inspecting Links and Loaded Modules

List the enabled directory in long format to identify symbolic links:

ls -l /etc/apache2/mods-enabled/

A typical entry displays an arrow pointing to a file in mods-available. To inspect one link's destination, use:

readlink -f /etc/apache2/mods-enabled/rewrite.load

To display modules currently reported as loaded by Apache, use:

sudo apache2ctl -M

To search for one module:

sudo apache2ctl -M | grep rewrite

Filesystem state and process state can differ temporarily. A link may appear in mods-enabled while the running Apache process still uses its previous configuration because no reload has occurred. A failed reload can also leave the old process running while the new filesystem configuration remains unapplied.

Module Lifecycle States

  • Not installed: The package and module definition are absent. There are no usable files in mods-available, and Apache cannot enable the module.
  • Installed but disabled: The package and available files exist, but no corresponding links exist in mods-enabled. Apache does not load the module after a successful reload.
  • Enabled: The available files exist and matching links exist in mods-enabled. After a successful reload, Apache should report the module as loaded.
  • Disabled after prior use: The links have been removed, but the package and available files remain. The module can usually be enabled again later.

Module Management Command Reference

  • Enable: sudo a2enmod module_name. Creates links for the selected module. Follow with a configuration test and reload.
  • Disable: sudo a2dismod module_name. Removes the module's enabled links. Follow with a configuration test and reload.
  • Validate: sudo apache2ctl configtest. Checks Apache configuration syntax and reports configuration errors.
  • Reload: sudo systemctl reload apache2. Applies a valid configuration to the running service.
  • List loaded modules: sudo apache2ctl -M. Shows modules loaded by the Apache configuration instance being inspected.

Safe Change Workflow

  1. Determine whether the required module is already available under /etc/apache2/mods-available.
  2. Install the appropriate package if the module is not available:
sudo apt-get install package_name
  1. Enable or disable the module with a2enmod or a2dismod rather than manually creating or deleting links.
  2. Run a configuration test:
sudo apache2ctl configtest
  1. Reload Apache only after the test succeeds:
sudo systemctl reload apache2
  1. Check service status and logs if the operation fails:
sudo systemctl status apache2
sudo journalctl -u apache2
  1. Verify the intended module with sudo apache2ctl -M, then test the affected site or application.

Worked Authentication-Module Example

For a modern authentication-related example, mod_authn_dbd can connect Apache authentication to a database access layer. The exact package providing database drivers varies by distribution release and database type. A SQLite-based Debian or Ubuntu setup may use a package such as libaprutil1-dbd-sqlite3, while the Apache module itself may already be supplied by the Apache package.

sudo apt-get install libaprutil1-dbd-sqlite3
sudo a2enmod authn_dbd
ls -l /etc/apache2/mods-enabled/ | grep authn_dbd
readlink -f /etc/apache2/mods-enabled/authn_dbd.load
sudo apache2ctl configtest
sudo systemctl reload apache2
sudo apache2ctl -M | grep authn_dbd

Installing the driver package does not necessarily activate authn_dbd. The module must be available, enabled, configured with suitable database settings, and then loaded through a successful reload. Do not copy this example without adapting the database provider and authentication configuration to the target system.

Historical auth_mysql Context

Older Apache configurations sometimes used a module named auth_mysql for MySQL-backed authentication. Treat this as a historical example only: package names, module names, and support status vary, and this module may not exist or be appropriate on current Debian and Ubuntu releases.

The general older workflow was still the same: install a package, enable the module separately, validate Apache configuration, and reload the service. For new systems, choose a currently supported authentication backend and follow documentation for the operating system release.

Troubleshooting

a2enmod Says the Module Does Not Exist

  • The required package may not be installed.
  • The identifier supplied to a2enmod may not match the available module filename.
  • The module may be unavailable in the configured repositories or retired on that release.

Inspect available definitions:

ls -1 /etc/apache2/mods-available/

Then search installed or repository packages and use the current module name for the operating system release.

Apache Fails to Reload

  • A newly enabled configuration may contain a syntax error.
  • The module may require another module or package dependency.
  • A directive may be unsupported by the installed Apache or module version.

Run the configuration test and inspect service diagnostics:

sudo apache2ctl configtest
sudo systemctl status apache2
sudo journalctl -u apache2

Correct the configuration or enable the required dependency. If necessary, disable the problematic module with a2dismod, validate again, and reload to restore the previous working state.

The Link Exists but the Module Is Not Loaded

Apache may not have been reloaded, may be using a different configuration instance, or may be skipping an invalid load directive. Check the link and its target, test the configuration, reload, and inspect the module list again:

readlink -f /etc/apache2/mods-enabled/module_name.load
sudo apache2ctl configtest
sudo systemctl reload apache2
sudo apache2ctl -M

A Website Stops Working After Disabling a Module

The site may use directives supplied by the disabled module, or another feature may depend on it. Review virtual host and .htaccess files, look for unknown-directive or authentication errors, and check the Apache error log or system journal.

Re-enable the required module if the site depends on it, or replace the module-specific configuration with a supported alternative before disabling it again.

Exam-Relevant Notes

  • mods-available means installed and available for activation; mods-enabled means selected for Apache to load.
  • Entries in mods-enabled are normally symbolic links to files in mods-available.
  • .load files commonly contain LoadModule; .conf files contain optional module settings.
  • a2enmod enables a module, while a2dismod disables it.
  • Use apache2ctl configtest before a reload whenever possible.
  • Use apache2ctl -M to inspect modules loaded by Apache, not merely links present on disk.
  • Changing a link does not alter the running process until Apache successfully reloads or restarts.

For the related Debian and Ubuntu layout, see the Apache mods-enabled directory reference.