How to enable or disable Apache modules
Apache, one of the most widely used web servers, offers a modular architecture that allows users to extend its functionality by enabling or disabling specific modules. These modules can range from security enhancements to performance optimizations and additional functionalities. Depending on the Linux distribution, Apache provides different methods to manage these modules.
The two primary methods to manage Apache modules are using the a2enmod and a2dismod commands, and manually editing the configuration files to load or unload modules. The former is a more straightforward approach, typically available on Debian-based systems, while the latter offers more control and is universal across all Apache installations. RedHat-based distributions do not have a2enmod and a2dismod, but provides a configuration file with LoadModule directive for every installed Apache modules.
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 (Apache 2 Enable Module) and a2dismod (Apache 2 Disable Module) commands are utilities provided by Debian and its derivatives, like Ubuntu, to simplify the process of enabling and disabling Apache modules. These commands automatically create symbolic links to the module configuration files, making the process seamless.
-
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 have the a2enmod and a2dismod utilities, or for administrators who prefer a hands-on approach, modules can be enabled or disabled by manually editing the Apache configuration files. This method involves adding or removing the LoadModule directive for the desired module.
-
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)