Apache is a widely used web server that supports a modular architecture. This allows administrators to add or remove specific functionalities by enabling or disabling modules. Managing these modules effectively is crucial for optimizing the performance and security of your Apache server. The process varies depending on the Linux distribution in use.
On Debian-based systems like Ubuntu, the a2enmod and a2dismod commands are available for managing modules. These commands simplify the process by automatically adjusting the configuration files. For distributions like RedHat and CentOS, module management requires manually editing the configuration files to add or remove LoadModule directives.
Understanding the differences in these methods ensures that you can effectively manage your Apache server in any environment. Whether through command-line utilities or manual configuration, these techniques allow you to control which modules are active, thereby tailoring the server to your specific needs.
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.loadactions.conf dir.load proxy_fcgi.loadactions.load dump_io.load proxy_fdpass.loadalias.conf echo.load proxy_ftp.confalias.load env.load proxy_ftp.loadallowmethods.load expires.load proxy_hcheck.loadasis.load ext_filter.load proxy_html.confauth_basic.load file_cache.load proxy_html.loadauth_digest.load filter.load proxy_http2.loadauth_form.load headers.load proxy_http.loadauthn_anon.load heartbeat.load proxy.loadauthn_core.load heartmonitor.load proxy_scgi.loadauthn_dbd.load http2.conf proxy_uwsgi.loadauthn_dbm.load http2.load proxy_wstunnel.load##### snipped
Related: How to view a list of modules in Apache
List enabled modules.
$ ls /etc/apache2/mods-enabled/access_compat.load authz_user.load filter.load proxy_http.loadalias.conf autoindex.conf mime.conf proxy.loadalias.load autoindex.load mime.load reqtimeout.confauth_basic.load deflate.conf mpm_event.conf reqtimeout.loadauthn_core.load deflate.load mpm_event.load setenvif.confauthn_file.load dir.conf negotiation.conf setenvif.loadauthz_core.load dir.load negotiation.load status.confauthz_host.load env.load proxy.conf status.load
Install module if not already installed.
See AlsoHow to Fix the “SSL Handshake Failed” and "Cloudflare 525" Error (5 Methods)SupportSteps to disable SSLv3 protocol (POODLE VULNERABILITY) on Appservers that are supported by Identity ManagerHow Do I Disable SSL for a Database?_Database Security Service_Huawei CloudRelated: How to install Apache modules
Enable module using a2enmod utility.
$ sudo a2enmod rewriteEnabling module rewrite.To activate the new configuration, you need to run: systemctl restart apache2
Disable module using a2enmod utility.
$ sudo a2dismod statusModule 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
Related: How to manage the Apache web server service
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.
See AlsoQualys DiscussionsRelated: 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
Related: How to manage the Apache web server service
Check if module is loaded or unloaded.
$ httpd -M | grep rewrite rewrite_module (shared)
Related: Apache binary name for different distribution
Related: How to view a list of modules in Apache
Discuss the article:
Comment anonymously. Login not required.