Table of Contents

How to enable or disable Apache modules

Enabling or disabling Apache modules controls which features the server can actually use, including URL rewriting, TLS, proxying, compression, and status reporting. Keeping only the modules you need reduces configuration sprawl and narrows the set of directives and request-processing hooks that Apache loads at startup.

Apache can load functionality either as built-in code or as shared modules declared with LoadModule. On Debian and Ubuntu, a2enmod and a2dismod toggle symlinks under /etc/apache2/mods-enabled; on openSUSE and SLES, the same helper commands update the APACHE_MODULES list in /etc/sysconfig/apache2; on RHEL-style packages, macOS, Homebrew, and XAMPP, module changes are usually made by editing LoadModule lines directly.

Some modules are static and cannot be toggled at all, and some shared modules depend on other modules or provide directives that existing site files still use. Test the configuration before you reload or restart Apache, and expect the exact control command to vary by packaging even when the module state change itself is the same.

Methods to enable or disable Apache modules:

Platform packaging style Preferred method What changes
Debian, Ubuntu a2enmod / a2dismod Symlinks under /etc/apache2/mods-enabled point to files in /etc/apache2/mods-available.
openSUSE, SLES a2enmod / a2dismod The helper scripts update APACHE_MODULES in /etc/sysconfig/apache2.
RHEL, Rocky Linux, AlmaLinux, CentOS Stream, Fedora Edit LoadModule lines Module declarations usually live under /etc/httpd/conf.modules.d/.
macOS bundled Apache Edit LoadModule lines Modules are declared in /etc/apache2/httpd.conf and related includes.
Homebrew httpd Edit LoadModule lines Module declarations usually live under /opt/homebrew/etc/httpd or /usr/local/etc/httpd.
XAMPP Edit LoadModule lines Module declarations are managed in the bundled /httpd.conf and related extra files.

Steps to enable or disable Apache modules:

Steps to enable or disable Apache modules using a2enmod and a2dismod:

This method is the normal workflow on Debian, Ubuntu, openSUSE, and SLES because the helper scripts keep the packaged module layout consistent with the server's expected configuration tree. It is the safest way to toggle packaged shared modules when the distribution provides the wrapper.

These commands only change whether an already installed module is activated. If the module definition file is missing, install the package first, then enable it, test the configuration, and restart or reload the service with the command your platform uses.

  1. List the module definition files that are available to enable.
    $ ls /etc/apache2/mods-available | sed -n '1,16p'
    access_compat.load
    actions.conf
    actions.load
    alias.conf
    alias.load
    allowmethods.load
    asis.load
    auth_basic.load
    auth_digest.load
    authn_core.load
    authn_file.load
    deflate.conf
    deflate.load
    dir.conf
    dir.load
    rewrite.load

    On openSUSE and SLES, a2enmod and a2dismod are still the preferred interface, but the active module list is stored in /etc/sysconfig/apache2 instead of a symlink tree.

  2. Check the current state of the target module before changing it.
    $ sudo a2query -m rewrite
    No module matches rewrite (disabled by site administrator)
  3. Install the package that provides the module if the corresponding .load file is missing.
  4. Enable the module with a2enmod.
    $ sudo a2enmod rewrite
    Enabling module rewrite.
    To activate the new configuration, you need to run:
      service apache2 restart
  5. Disable the module with a2dismod when the feature is no longer needed.
    $ sudo a2dismod rewrite
    Module rewrite disabled.
    To activate the new configuration, you need to run:
      service apache2 restart

    If another enabled module depends on the target module, a2dismod can refuse the change until you disable the dependent module first or deliberately use --force.

  6. Test the Apache configuration syntax before applying the module change.
    $ sudo apache2ctl configtest
    AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 192.0.2.10. Set the 'ServerName' directive globally to suppress this message
    Syntax OK

    The AH00558 line is a hostname warning, not a syntax failure.

  7. Restart the Apache service so the new module set is loaded.
    $ sudo systemctl restart apache2

    The helper output often suggests service apache2 restart; on systemd hosts, systemctl restart apache2 is the same service action.

  8. Verify the final module state with a2query or the loaded module list.
    $ sudo a2query -m rewrite
    rewrite (enabled by site administrator)

    After a disable, the same query reports No module matches rewrite (disabled by site administrator).

Steps to enable or disable Apache modules manually:

Use the manual method on platforms that do not ship a2enmod and a2dismod as the primary interface, including RHEL-style packages, the bundled Apache on macOS, Homebrew httpd, and many XAMPP installs. The workflow is the same everywhere: find the relevant LoadModule declaration, comment it out to disable the module, or uncomment or add it to enable the module.

Manual editing is also the fallback when you are working with third-party or custom-built modules that are not represented by a packaged helper script. Shared modules appear as shared in httpd -M or apachectl -M output, while static modules are built into the binary and cannot be removed with a configuration edit.

  1. Search the active configuration tree for the module's LoadModule line.
    $ sudo grep -RIn "LoadModule rewrite_module" /etc/httpd/conf.modules.d /etc/apache2 /opt/homebrew/etc/httpd /usr/local/etc/httpd 2>/dev/null
    /etc/httpd/conf.modules.d/00-base.conf:51:LoadModule rewrite_module modules/mod_rewrite.so

    Common locations include /etc/httpd/conf.modules.d/ on RHEL-style systems, /etc/apache2/httpd.conf on bundled macOS Apache, and /opt/homebrew/etc/httpd/httpd.conf or /usr/local/etc/httpd/httpd.conf on Homebrew.

  2. Install the package that provides the module if the .so file or LoadModule line is not present yet.
  3. Open the file that owns the LoadModule declaration.
    $ sudoedit /etc/httpd/conf.modules.d/00-base.conf
  4. Comment out the LoadModule line to disable the module.
    #LoadModule rewrite_module modules/mod_rewrite.so

    If any enabled site, include file, or .htaccess file still uses directives from that module, the next config test can fail with an Invalid command error.

  5. Uncomment the existing LoadModule line or add a new one to enable the module.
    LoadModule rewrite_module modules/mod_rewrite.so

    Packaged modules usually use a relative path under modules/, while third-party modules often need an absolute path supplied by the package or build instructions.

  6. Test the configuration syntax with the control wrapper your platform provides.
    $ sudo httpd -t
    AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.0.2.10. Set the 'ServerName' directive globally to suppress this message
    Syntax OK

    Use sudo apachectl configtest or sudo apachectl -t on macOS, Homebrew, or XAMPP when those platforms do not ship the httpd wrapper as the default admin command.

  7. Restart Apache with the service command that matches your packaging.
    $ sudo systemctl restart httpd
    $ sudo apachectl restart
    $ brew services restart httpd

    RHEL-style packages usually use httpd, bundled macOS Apache uses apachectl, and current Homebrew guidance uses brew services restart httpd for the background service.

  8. Confirm that the module is now loaded or absent in the running server.
    $ sudo httpd -M | grep rewrite
     rewrite_module (shared)

    On macOS and Homebrew, run apachectl -M | grep rewrite instead; if the module is disabled, the command returns no matching line.