2026年11月12日

2026年11月12日

How to Enable and Disable Apache Modules (a2enmod, a2dismod, LoadModule)

This article is a localized edition of the Japanese original. Read the Japanese original

Apache httpd (Apache from here on) provides features such as URL rewriting (mod_rewrite) and HTTPS (mod_ssl) as "modules". Loading only the modules you use keeps your configuration easier to follow and lets you remove features you don't need.

How you enable and disable modules depends on the OS (distribution). This article covers Ubuntu/Debian and AlmaLinux, Rocky Linux and other RHEL-based systems. Everything here applies to Apache 2.4, and the commands are run with root privileges (sudo).

Ubuntu and Debian (a2enmod, a2dismod)

In Apache on Ubuntu and Debian (package name apache2), module configuration is split across two directories.

Directory Contents
/etc/apache2/mods-available/ Configuration for installed modules (.load and .conf)
/etc/apache2/mods-enabled/ Enabled modules (symbolic links to mods-available)

a2enmod creates a symbolic link in mods-enabled, and a2dismod removes it. You don't need to edit files by hand.

Check which modules are enabled

# List enabled modules (as set in the configuration files)
a2query -m

# Check whether a specific module is enabled
a2query -m rewrite

# Modules Apache actually loads (including statically compiled ones)
apache2ctl -M

# List modules that can be enabled
ls /etc/apache2/mods-available/

apache2ctl -M fails if the configuration contains an error. In that case, use apache2ctl configtest, described in the next section, to find where the error is.

Enable a module

# Enable one module (example: mod_rewrite)
sudo a2enmod rewrite

# Enable several modules at once (example: mod_ssl and mod_headers)
sudo a2enmod ssl headers

# Check the configuration syntax
sudo apache2ctl configtest

# Restart once it shows Syntax OK
sudo systemctl restart apache2

Write module names without the mod_ prefix (rewrite for mod_rewrite). Specifying a module that is already enabled is not an error. If a module has dependencies, they are enabled too (for example, enabling ssl also enables socache_shmcb and other modules it needs).

After you run a2enmod, it tells you to run systemctl restart apache2 to apply the change. Confirming Syntax OK with configtest before restarting keeps a configuration mistake from leaving Apache unable to start.

Disable a module

# Disable one module (example: mod_status)
sudo a2dismod status

# Check the configuration and restart
sudo apache2ctl configtest
sudo systemctl restart apache2

If directives (settings) for a disabled module remain in a virtual host or .htaccess, Apache may fail to start or return 500 errors. For example, disabling mod_rewrite breaks the RewriteRule lines in the .htaccess that WordPress uses for permalinks. Before disabling a module, check for directives in your configuration that are not wrapped in <IfModule mod_rewrite.c>.

# Example: find configuration files that use rewrite directives
grep -rn "Rewrite" /etc/apache2/sites-enabled/ /etc/apache2/conf-enabled/

A module that other modules depend on usually can't be disabled as is. a2dismod -f also disables the modules that depend on it, so check what will stop working before you use it.

Switch the MPM

The MPM (Multi-Processing Module) decides how Apache handles requests. Only one of mpm_event, mpm_worker and mpm_prefork is enabled at a time. You can check the current MPM with this command:

a2query -M

If you run PHP as an Apache module (libapache2-mod-php), you need mpm_prefork. To use mpm_event, switch to running PHP through PHP-FPM. When switching MPMs, disable the current MPM first and then enable the other one.

# Example: switch from prefork to event (when using PHP-FPM)
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event
sudo apache2ctl configtest
sudo systemctl restart apache2

You can't switch to mpm_event while the PHP module is still enabled (either a2dismod reports a dependency error, or configtest reports that the MPM and the PHP module are incompatible). First disable the PHP module with a command such as a2dismod php8.3 (adjust the version to your system), finish setting up PHP-FPM, and then switch.

AlmaLinux, Rocky Linux and RHEL (LoadModule)

Apache on RHEL-based systems (package name httpd) has no a2enmod. Modules are loaded by LoadModule lines in the .conf files under /etc/httpd/conf.modules.d/.

# List loaded modules
httpd -M

# Find which file loads a module (example: status)
grep -rn "status_module" /etc/httpd/conf.modules.d/

Disable a module

Comment out the relevant LoadModule line by adding # at the start.

# Example from /etc/httpd/conf.modules.d/00-base.conf
#LoadModule status_module modules/mod_status.so
sudo apachectl configtest
sudo systemctl restart httpd

File names and which modules go in which file vary by OS version. Find the line with grep before editing, and keep a copy of the original file.

Enable a module

Remove the # from the commented-out line. Modules that aren't installed by default are added as packages. For example, mod_ssl for HTTPS is a separate package.

sudo dnf install mod_ssl
sudo apachectl configtest
sudo systemctl restart httpd

Installing the package adds a configuration file containing the LoadModule line to /etc/httpd/conf.modules.d/.

What to check after a change

  1. apache2ctl configtest (apachectl configtest on RHEL-based systems) shows Syntax OK
  2. apache2ctl -M (httpd -M on RHEL-based systems) lists the modules you enabled and not the ones you disabled
  3. Your site still works as before, including permalinks and HTTPS

If the restart fails, look at the error details.

# Ubuntu / Debian
sudo systemctl status apache2
sudo journalctl -u apache2 -n 50
sudo tail -n 50 /var/log/apache2/error.log

# RHEL-based
sudo systemctl status httpd
sudo tail -n 50 /var/log/httpd/error_log

If you see "Invalid command", as in Invalid command 'RewriteEngine', the module that provides that directive is disabled. Re-enable the module or remove the setting.

Examples of modules you might disable

Which modules you don't need depends on your setup. The following are examples only. Check your configuration files to confirm a module isn't in use before deciding.

Module Purpose OK to disable when
status Shows server status at /server-status You don't use it for monitoring
autoindex Generates file listings automatically You don't need to show directory listings
userdir Publishes each user's pages at ~username URLs You don't use it
cgi / cgid Runs CGI programs You don't use CGI

To run WordPress, keep rewrite (permalinks) enabled. If Apache terminates HTTPS you also need ssl, and with PHP-FPM you also need proxy and proxy_fcgi.

Related articles

Questions about WordPress? The publisher of this site is based in Japan and replies in Japanese. Contact (Japanese)

お気軽にご相談ください

お見積りへ お問い合わせへ
▲