Apache modules supply server features such as URL rewriting, TLS, and proxying. Enabling or disabling a module changes the available features and requires applying and verifying the chosen final state.

Apache can load functionality as built-in code or as shared modules declared with LoadModule. Debian and Ubuntu manage packaged shared modules with symlinks, while openSUSE and SLES maintain a module list through their own helper scripts. RHEL-family packages use LoadModule configuration files directly.

Modules marked static are built into Apache and cannot be disabled through configuration. Disabling a shared module can break sites that depend on its directives or features, including rules in .htaccess files that a syntax test does not exercise. A failed configuration test or reload means the intended change is not ready; the previous helper state or LoadModule line provides a reversible change.

Steps to enable or disable Apache modules:

The Apache service must already be installed and running. Each method uses rewrite as the target module; substitute the installed module you need. Package installation belongs in How to install Apache modules on Ubuntu and Debian, and the complete URL-rewriting setup belongs in How to enable mod_rewrite in Apache.

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

This method applies to Debian and Ubuntu. Their helpers create or remove symlinks in /etc/apache2/mods-enabled using module definitions in /etc/apache2/mods-available. An a2query result describes that helper configuration, not whether the change has reached Apache.

  1. Confirm that the target module has an installed definition file.
    $ ls /etc/apache2/mods-available/rewrite.load
    /etc/apache2/mods-available/rewrite.load

    A missing file means the module is not available through this configuration tree.

  2. Apply the desired module state with a2enmod (enable) or a2dismod (disable).

    For the enabled state:

    $ sudo a2enmod rewrite
    Enabling module rewrite.
    To activate the new configuration, you need to run:
      systemctl restart apache2

    For the disabled state instead:

    $ sudo a2dismod rewrite
    Module rewrite disabled.
    To activate the new configuration, you need to run:
      systemctl restart apache2

    These are alternatives, not consecutive steps. The name is rewrite, not mod_rewrite or rewrite_module. A dependency refusal from a2dismod needs investigation before disabling other modules.

  3. Test the Apache configuration syntax.
    $ sudo apache2ctl configtest
    Syntax OK

    The AH00558 hostname warning can appear before Syntax OK on an otherwise valid configuration. A syntax error must be corrected, or the module change reversed, before a reload.

  4. Reload the Apache service to apply the chosen module state.
    $ sudo systemctl reload apache2

    A reload is sufficient for this shared-module change even though the helper suggests a restart. If the reload fails, Apache may still be using its previous configuration.

  5. Verify the target module in the loaded-module list after the successful reload.
    $ sudo apachectl -M
    Loaded Modules:
     core_module (static)
     so_module (static)
    ##### snipped #####
     rewrite_module (shared)
    ##### snipped #####

    This output shows the enabled state. For a disable, rewrite_module must be absent from the complete list. -M loads the configuration for inspection; it does not query an existing server process, so a successful reload is essential.

Steps to enable or disable Apache modules on openSUSE and SLES:

The SUSE helpers update APACHE_MODULES in /etc/sysconfig/apache2 instead of Debian's symlink tree. The packaged service regenerates its module-loading configuration when it applies this list; a2query and /etc/apache2/mods-available are not part of this method.

  1. Apply the desired module state with a2enmod (enable) or a2dismod (disable).

    For the enabled state:

    $ sudo a2enmod rewrite

    For the disabled state instead:

    $ sudo a2dismod rewrite

    These are alternatives, not consecutive steps. The helpers may finish without printing a confirmation.

  2. Test the Apache configuration syntax.
    $ sudo apachectl configtest
    Syntax OK

    A syntax error must be corrected, or the helper change reversed, before a reload.

  3. Reload the Apache service to apply the module list.
    $ sudo systemctl reload apache2

    If the reload fails, the new helper state does not prove that Apache applied it.

  4. Verify the target module in the loaded-module list after the successful reload.
    $ sudo apachectl -M
    Loaded Modules:
     core_module (static)
     so_module (static)
    ##### snipped #####
     rewrite_module (shared)

    The enabled state includes rewrite_module (shared). The disabled state has no rewrite_module line. This configuration inspection must follow a successful reload.

Steps to enable or disable Apache modules manually:

On RHEL-family systems such as Rocky Linux and AlmaLinux, packaged module declarations live under /etc/httpd/conf.modules.d/. An a2enmod: command not found message on these systems is expected; the LoadModule edit replaces the helper operation. Other Apache installations can use different configuration locations and service controls.

  1. Locate the target module's LoadModule declaration. Example output:
    $ sudo grep -RIn "LoadModule rewrite_module" /etc/httpd/conf.modules.d
    /etc/httpd/conf.modules.d/00-base.conf:52:LoadModule rewrite_module modules/mod_rewrite.so

    The filename and line number can vary. A missing module binary or declaration belongs to How to install Apache modules on Ubuntu and Debian.

  2. Back up the configuration file that contains the declaration.
    $ sudo cp -p /etc/httpd/conf.modules.d/00-base.conf /etc/httpd/conf.modules.d/00-base.conf.bak

    The .bak suffix keeps this copy outside the packaged *.conf include pattern. The original line remains available if the edit needs to be reversed.

  3. Open the module configuration file in your editor.
    $ sudoedit /etc/httpd/conf.modules.d/00-base.conf
  4. Set the existing rewrite_module declaration to your chosen state.

    For the enabled state, the line has no comment marker:

    LoadModule rewrite_module modules/mod_rewrite.so

    For the disabled state instead, the same line starts with #:

    #LoadModule rewrite_module modules/mod_rewrite.so

    Only one of these states belongs in the file. An additional active LoadModule line elsewhere can keep the module enabled.

  5. Save the configuration file.
  6. Test the Apache configuration syntax.
    $ sudo apachectl configtest
    Syntax OK

    A syntax error must be corrected, or the original declaration restored, before a reload.

  7. Reload the httpd service to apply the module change.
    $ sudo systemctl reload httpd

    A failed reload can leave the old configuration running.

  8. Verify the target module in the loaded-module list after the successful reload.
    $ sudo httpd -M
    Loaded Modules:
     core_module (static)
     so_module (static)
    ##### snipped #####
     rewrite_module (shared)
    ##### snipped #####

    The enabled state includes rewrite_module (shared); the disabled state omits that line. Current RHEL-family apachectl wrappers can reject -M, so this method uses httpd -M. The command inspects the configuration rather than querying the running process.

Share this guide