Toggling Apache modules enables features such as TLS, proxying, compression, and URL rewriting while keeping unused components unloaded to reduce complexity and attack surface.
Most modules are loaded as shared objects and activated through configuration, either via helper tools like a2enmod and a2dismod or by adding and removing LoadModule directives that point to the module’s .so file.
Module management is distribution-specific and mistakes can prevent Apache from starting, especially when configuration files reference directives provided by a module that has been disabled; run a configuration test before restarting and note that some modules are compiled in and cannot be toggled.
Related: How to view a list of modules in Apache
Related: How to manage the Apache web server service
Related: Apache configuration file locations
| Platform packaging style | Preferred method | Where it takes effect |
|---|---|---|
| Debian, Ubuntu | a2enmod / a2dismod | Symlinks in /etc/apache2/mods-enabled pointing to /etc/apache2/mods-available. |
| openSUSE, SLES | a2enmod / a2dismod | Module list/flags stored in /etc/sysconfig/apache2 and applied by the startup scripts. |
| Fedora, CentOS, RHEL | Edit LoadModule lines | Usually /etc/httpd/conf.modules.d/ and /etc/httpd/conf/httpd.conf. |
| macOS (Apple-supplied) | Edit LoadModule lines | Usually /etc/apache2/httpd.conf. |
| Homebrew | Edit LoadModule lines | Commonly /opt/homebrew/etc/httpd/httpd.conf or /usr/local/etc/httpd/httpd.conf. |
| XAMPP | Edit LoadModule lines | Controlled by the bundled /httpd.conf and module directory. |
Steps to enable or disable Apache modules using a2enmod and a2dismod:
- List available modules from /etc/apache2/mods-available.
$ ls /etc/apache2/mods-available/ access_compat.load actions.conf actions.load alias.conf alias.load allowmethods.load asis.load auth_basic.load auth_digest.load auth_form.load authn_anon.load authn_core.load authn_dbd.load authn_dbm.load authn_file.load authn_socache.load authnz_fcgi.load authnz_ldap.load ##### snipped #####
openSUSE and SLES also provide a2enmod and a2dismod but typically manage the module list in /etc/sysconfig/apache2.
- List enabled modules from /etc/apache2/mods-enabled.
$ ls /etc/apache2/mods-enabled/ access_compat.load alias.conf alias.load auth_basic.load authn_core.load authn_file.load authz_core.load authz_host.load authz_user.load autoindex.conf autoindex.load deflate.conf deflate.load dir.conf dir.load env.load filter.load mime.conf mime.load ##### snipped #####
- Install the module package if the module is not present in /etc/apache2/mods-available.
Related: How to install Apache modules
- Enable a module with a2enmod.
$ sudo a2enmod rewrite Module rewrite already enabled
- Disable a module with a2dismod.
$ sudo a2dismod status Module status disabled. To activate the new configuration, you need to run: systemctl restart apache2
Disabling a module that provides active configuration directives can prevent apache2 from starting with “Invalid command” errors.
- Test the apache2 configuration syntax.
$ sudo apache2ctl configtest Syntax OK
- Restart apache2 to apply the module change.
$ sudo systemctl restart apache2
- Verify the module state with a2query.
$ sudo a2query -m rewrite rewrite (enabled by site administrator)
- On RHEL-style systems, confirm the service and loaded modules with httpd tooling.
$ sudo systemctl status httpd --no-pager -l ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: disabled) Active: active (running) since Sun 2026-01-11 05:51:55 +08; 11s ago Docs: man:httpd.service(8) Main PID: 164180 (httpd) Tasks: 177 (limit: 10555) Memory: 14.1M (peak: 14.9M) CPU: 61ms $ sudo httpd -M | grep -E 'mpm_|status|rewrite' rewrite_module (shared) status_module (shared) mpm_event_module (shared)
Steps to enable or disable Apache modules manually:
- Locate the module’s LoadModule line in the active configuration tree.
$ sudo grep -nr LoadModule /etc/httpd /etc/httpd/conf/httpd.conf:53:# have to place corresponding `LoadModule' lines at this location so the /etc/httpd/conf/httpd.conf:59:# LoadModule foo_module modules/mod_foo.so /etc/httpd/conf.modules.d/00-base.conf:6:LoadModule access_compat_module modules/mod_access_compat.so /etc/httpd/conf.modules.d/00-base.conf:7:LoadModule actions_module modules/mod_actions.so /etc/httpd/conf.modules.d/00-base.conf:8:LoadModule alias_module modules/mod_alias.so /etc/httpd/conf.modules.d/00-base.conf:9:LoadModule allowmethods_module modules/mod_allowmethods.so /etc/httpd/conf.modules.d/00-base.conf:10:LoadModule auth_basic_module modules/mod_auth_basic.so /etc/httpd/conf.modules.d/00-base.conf:11:LoadModule auth_digest_module modules/mod_auth_digest.so /etc/httpd/conf.modules.d/00-base.conf:12:LoadModule authn_anon_module modules/mod_authn_anon.so /etc/httpd/conf.modules.d/00-base.conf:13:LoadModule authn_core_module modules/mod_authn_core.so /etc/httpd/conf.modules.d/00-base.conf:14:LoadModule authn_dbd_module modules/mod_authn_dbd.so /etc/httpd/conf.modules.d/00-base.conf:15:LoadModule authn_dbm_module modules/mod_authn_dbm.so ##### snipped #####
Paths commonly differ on macOS (/etc/apache2/httpd.conf) and Homebrew (/opt/homebrew/etc/httpd/httpd.conf or /usr/local/etc/httpd/httpd.conf).
- Install the module package if the module file is not present under the modules directory.
Related: How to install Apache modules
- Open the configuration file that contains the module’s LoadModule directive.
$ sudo vi /etc/httpd/conf.modules.d/00-base.conf
- Comment out the module’s LoadModule line to disable it.
#LoadModule rewrite_module modules/mod_rewrite.soRemoving a required module can stop httpd from starting if any configuration still uses that module’s directives.
- Uncomment the module’s LoadModule line to re-enable it.
LoadModule rewrite_module modules/mod_rewrite.so - Add a LoadModule line for an installed module that is not referenced by any configuration file.
LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.soThe module path varies by packaging and CPU architecture, so confirm the actual .so location before saving.
Related: Location for Apache modules
- Test the httpd configuration syntax.
$ sudo httpd -t Syntax OK
- Restart the service to apply the change.
$ sudo systemctl restart httpd
Service name is commonly httpd on Fedora, CentOS, and RHEL and apache2 on Debian and Ubuntu.
- Confirm that the module is loaded or unloaded.
$ sudo httpd -M | grep rewrite rewrite_module (shared)
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
