How to Disable an Apache Module on Debian or Ubuntu
This guide provides a quick overview of how to disable a module in the Apache HTTP Server on Debian-based Linux distributions, such as Ubuntu. Disabling unnecessary modules is a key step in optimizing server performance and improving security. By using the built-in Debian Apache management scripts, administrators can safely disable modules and restart the service with minimal downtime.
Step 1: List Enabled Apache Modules
Before disabling a module, it is helpful to verify the exact name of the module currently enabled on your system. You can list all active Apache modules by running the following command in your terminal:
apache2ctl -MAlternatively, you can view the symbolic links in the
mods-enabled directory to see what is currently active:
ls /etc/apache2/mods-enabled/Step 2: Use the a2dismod Command
Debian and Ubuntu systems include a dedicated script called
a2dismod (Apache2 Disable Module) specifically designed for
this task. This script removes the symbolic link from the
/etc/apache2/mods-enabled/ directory, which tells Apache
not to load the module upon the next restart.
To disable a module, run the command followed by the name of the
module. For example, to disable the status module,
execute:
sudo a2dismod statusIf the module has dependencies that other active modules rely on, the script will warn you before proceeding.
Step 3: Test the Apache Configuration
It is best practice to test your Apache configuration files for syntax errors before restarting the web server. Disabling certain modules can sometimes cause configuration errors if other configuration files still reference the disabled module.
Run the following test command:
sudo apache2ctl configtestIf the output returns Syntax OK, it is safe to proceed
to the final step.
Step 4: Restart or Reload Apache
The changes will not take effect until the Apache service is reloaded or restarted. To minimize disruption to active web traffic, a graceful reload is recommended:
sudo systemctl reload apache2If you prefer a full restart of the service, use the following command instead:
sudo systemctl restart apache2