Apache is a widely adopted web server that uses a modular architecture to extend or limit functionality through individual modules. It supports a range of distributions and environments, each requiring different methods to load or unload specific components. Careful module management helps optimize performance, reduce resource consumption, and improve overall security.
On Debian-based systems such as Ubuntu, the a2enmod and a2dismod commands automate the process by creating or removing symbolic links in the server’s configuration directories. Meanwhile, RedHat, CentOS, and openSUSE often rely on manual editing of LoadModule directives within Apache configuration files to achieve the same result.
This flexibility allows administrators to tailor Apache precisely to operational requirements. Selectively enabling or disabling modules can reduce the attack surface while conserving system resources. Each distribution offers distinct advantages for controlling which modules are active, but the core principles remain consistent across all environments.
Options | Debian, Ubuntu | openSUSE and SLES | Fedora Core, CentOS, RHEL | macOS | homebrew | xampp |
---|---|---|---|---|---|---|
a2enmod support | yes | yes | no | no | no | no |
Loadmodule directive | n/a | LoadModule <module_name>_module <module_location>/mod_<module_name>.so |
Steps to enable or disable Apache modules using a2enmod and a2dismod:
The a2enmod command is used to enable an Apache module, while a2dismod is used to disable a module. These commands are specific to Debian-based systems such as Ubuntu. They work by creating or removing symbolic links in the Apache configuration directory. This method is quick and straightforward, making it a preferred choice for many administrators.
To manage Apache modules using these commands, first, ensure that the desired module is installed. Then, use a2enmod to enable the module or a2dismod to disable it. Finally, restart the Apache service to apply the changes.
- List available modules.
$ ls /etc/apache2/mods-available/ access_compat.load dir.conf proxy_express.load actions.conf dir.load proxy_fcgi.load actions.load dump_io.load proxy_fdpass.load alias.conf echo.load proxy_ftp.conf alias.load env.load proxy_ftp.load allowmethods.load expires.load proxy_hcheck.load asis.load ext_filter.load proxy_html.conf auth_basic.load file_cache.load proxy_html.load auth_digest.load filter.load proxy_http2.load auth_form.load headers.load proxy_http.load authn_anon.load heartbeat.load proxy.load authn_core.load heartmonitor.load proxy_scgi.load authn_dbd.load http2.conf proxy_uwsgi.load authn_dbm.load http2.load proxy_wstunnel.load ##### snipped
- List enabled modules.
$ ls /etc/apache2/mods-enabled/ access_compat.load authz_user.load filter.load proxy_http.load alias.conf autoindex.conf mime.conf proxy.load alias.load autoindex.load mime.load reqtimeout.conf auth_basic.load deflate.conf mpm_event.conf reqtimeout.load authn_core.load deflate.load mpm_event.load setenvif.conf authn_file.load dir.conf negotiation.conf setenvif.load authz_core.load dir.load negotiation.load status.conf authz_host.load env.load proxy.conf status.load
- Install module if not already installed.
Related: How to install Apache modules
- Enable module using a2enmod utility.
$ sudo a2enmod rewrite Enabling module rewrite. To activate the new configuration, you need to run: systemctl restart apache2
- Disable module using a2enmod utility.
$ sudo a2dismod status Module status disabled. To activate the new configuration, you need to run: systemctl restart apache2
- Reload or restart the Apache service to apply the changes.
$ sudo systemctl restart apache2
- Check if modules are loaded.
$ sudo a2query -m rewrite [sudo] password for user: rewrite (enabled by site administrator)
Steps to enable or disable Apache modules manually:
For systems that do not support a2enmod and a2dismod, module management requires manual editing of the Apache configuration files. This method is universal and works across all Linux distributions. It involves adding or removing LoadModule directives in the appropriate configuration files.
To manually enable or disable a module, open the configuration file where the LoadModule directive is located. Add the directive to enable the module, or comment it out to disable it. After making changes, restart the Apache service to apply them.
- Open the terminal.
- Install module if not already installed.
Related: How to install Apache modules
- Check for existing LoadModule directives.
$ sudo grep -nr LoadModule /etc/{httpd,apache2} /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
- Open the Apache configuration file containing the LoadModule directive of the module that you want to enable or disable using your preferred text editor.
$ sudo vi /etc/httpd/conf.modules.d/00-base.conf
- Comment out the LoadModule directive associated with the module to disable a module.
#LoadModule rewrite_module modules/mod_rewrite.so
- Uncomment a commented LoadModule directive to re-enable a module.
LoadModule rewrite_module modules/mod_rewrite.so
- Manually add a LoadModule directive for module that is installed but without a pre-configured LoadModule directive such as in homebrew.
LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so "Mohd Shakir Zakaria"
Related: Location for Apache modules
- Save and close the configuration file.
- Restart the Apache service to apply the changes.
$ sudo systemctl restart apache2
- Check if module is loaded or unloaded.
$ 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.
Comment anonymously. Login not required.