Apache modules add features to the web server, and on Debian and Ubuntu you enable one with sudo a2enmod <name> followed by a reload. The command creates a symlink from mods-available to mods-enabled, so you never edit the main config by hand. Use a2dismod to turn a module off again and apache2ctl -M to see what is loaded.
Apache itself is small. Rewriting URLs, serving over TLS, proxying, compression and security headers all come from modules that load when the server starts. Knowing how to manage them is a core administration skill for the a2enmod apache modules workflow on Debian-family systems.
Apache loads modules with the LoadModule directive. The Debian packaging splits that into two directories under /etc/apache2/:
| Directory | Purpose |
|---|---|
mods-available/ | One .load file (and often a .conf file) per installed module |
mods-enabled/ | Symlinks to the modules that Apache actually loads |
The main apache2.conf includes everything in mods-enabled/. A module is therefore "enabled" simply because a symlink exists. Red Hat based systems (RHEL, Rocky, AlmaLinux) do not ship a2enmod; there you add LoadModule lines in /etc/httpd/conf.modules.d/ instead.
Some modules are compiled into the binary (static) and cannot be disabled. Most are shared objects (.so files) loaded at start up, which is what a2enmod controls.
Before you enable anything, check what is already there.
The last command prints names such as rewrite_module (shared). Note the suffix: a2enmod rewrite loads rewrite_module. The short name you pass to a2enmod is the file name without .load, not the module identifier.
Run the command with the module name, then check the configuration and reload.
Typical output:
The message says restart, but a reload is enough for most modules. Use a full restart when the module is new to the process, for example mpm_event, http2 or ssl the very first time, because some modules change process-level behaviour that a graceful reload does not apply. When in doubt, restart in a maintenance window.
You can pass several names in one call. If a module has dependencies, a2enmod enables them too: enabling proxy_http also enables proxy.
| Module | What it does | Typical use |
|---|---|---|
rewrite | URL rewriting with RewriteRule | Clean URLs, redirects, framework front controllers |
ssl | TLS support | HTTPS virtual hosts |
headers | Set or remove HTTP headers | Security headers, CORS |
deflate | Compress responses | Faster text transfers |
expires | Cache lifetime headers | Browser caching of static files |
proxy, proxy_http | Forward requests to another server | Reverse proxy to an app |
http2 | HTTP/2 support | Faster page loads over TLS |
remoteip | Trust a proxy for the client IP | Sites behind a load balancer |
Enabling a module only makes its directives available. You still have to use them. This example turns on compression and security headers for one site.
The IfModule wrapper keeps the file valid even if the module is missing, but it also hides mistakes: if you forgot a2enmod headers, Apache starts fine and silently ignores the block. During setup, leave the wrapper out so that a missing module fails the config test loudly.
Verify with curl -sI https://example.com/ and look for the header in the response.
Turn a module off with a2dismod, then reload:
Disabling modules you do not use shrinks the attack surface and memory use. Do not disable a module that other enabled configs depend on; the config test will report it.
Common errors and fixes:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration: the module is not enabled. Run sudo a2enmod rewrite.Module xyz does not exist!: the package that provides it is not installed. For example, install libapache2-mod-security2 before a2enmod security2.mods-available/ for a module that is not enabled, or a .htaccess file is blocked because AllowOverride is None.mpm_prefork, mpm_worker and mpm_event can be active. Switch with a2dismod mpm_prefork and a2enmod mpm_event, and note that classic mod_php needs prefork while PHP-FPM works with event.a2enmod manages modules in mods-enabled/. a2ensite manages virtual host files in sites-enabled/. Both work by creating symlinks.
A reload usually works. Restart for process-level modules such as an MPM, and whenever a reload does not make the new directives take effect.
The module file is not installed. Search with apt search libapache2-mod and install the matching package.
No. Add or remove LoadModule lines in /etc/httpd/conf.modules.d/ and reload httpd.
On Debian and Ubuntu, a2enmod links a module from mods-available into mods-enabled, and a2dismod removes the link. Always run apache2ctl configtest before reloading, confirm with apache2ctl -M, and avoid IfModule wrappers while setting up so missing modules show up as errors instead of silent no-ops.