Declutter Apache Modules means removing unused extensions from your server configuration to free up memory and reduce attack surface, but most people simply disable them in the config file without restarting, which leaves the code loaded in memory.
Apache loads modules at startup based on the configuration files. If you add a module to a file but do not restart the server, the change has no effect. To actually remove a module, you must edit the configuration, restart Apache, and verify the change took effect.
How to Find Which Modules Are Loaded
Before you can remove modules, you need to know which ones are active on your server. The most reliable way is to use the server status page if you have access to it, or to generate a module list from the command line.
- Open a terminal on the server.
- Run the following command to list all compiled-in modules that are currently active:
apache2ctl -MThis command outputs a space-separated list of module names that are currently loaded. For example, you might see
rewrite_module (shared)orexpires_module (shared). - Look for modules that match the names of extensions you do not use. Common candidates include
autoindex(directory listings),userdir(user home directories), orinfo(server information pages).
How to Disable or Configure Modules in the Main Config
Once you have identified a module to remove, you must edit the Apache configuration file. The exact location of this file depends on your operating system and how Apache was installed, but it is usually /etc/apache2/apache2.conf on Debian/Ubuntu or /etc/httpd/conf/httpd.conf on RHEL/CentOS.
- Open the main configuration file with a text editor as root:
sudo nano /etc/apache2/apache2.conf - Find the section that defines modules. It typically starts with a comment like
# Load modulesorLoadModulelines at the top of the file. - Comment out the line that loads the module you want to disable by adding a hash symbol (
#) to the beginning of the line. For example, to disable the autoindex module, change:LoadModule autoindex_module modules/mod_autoindex.soto:
# LoadModule autoindex_module modules/mod_autoindex.so - Save the file and exit the editor.
How to Restart Apache to Apply Changes
Modifying the configuration file does not take effect until you reload or restart the Apache service. The method you use depends on your operating system.
- On Debian/Ubuntu, use the following command to reload the configuration:
sudo systemctl reload apache2This command reloads the configuration without dropping existing connections. If you see no output, the reload was successful.
- On RHEL/CentOS, use the following command:
sudo systemctl reload httpd - On some systems, you may need to restart the service completely to ensure the module is unloaded. Use:
sudo systemctl restart apache2This will stop the service, start it again, and load the new configuration.
- Check the server status again with
apache2ctl -Mto confirm the module is no longer listed.
How to Check if a Module Is Needed by a Site
Disabling a module might break your websites if they rely on that module. Before you remove a module, verify that no configuration files or site-specific directives depend on it.
- Navigate to the site configuration directory. On Debian/Ubuntu, this is usually
/etc/apache2/sites-available. On RHEL/CentOS, it is/etc/httpd/conf.d. - Open each
.conffile in that directory with a text editor. - Use the search function in your editor to look for the module name. For example, search for
mod_rewriteormod_expires. - If you find references to the module, you must keep it enabled or find an alternative way to achieve the same effect. For example, if a site uses
mod_rewritefor pretty URLs, you cannot disable that module without rewriting your URLs.
How to Verify the Server Is Still Working After Decluttering
After disabling modules, it is important to confirm that your websites are still accessible and serving content correctly.
- Open a web browser on a machine that has access to the server.
- Enter the URL of your website. If the site loads without errors, the basic operation is intact.
- Check the server error logs for any issues. On Debian/Ubuntu, the logs are typically in
/var/log/apache2/. On RHEL/CentOS, they are in/var/log/httpd/. - Look for errors related to missing modules, such as
[core:notice] AH00052: child pid ... exited with status 1or permission denied errors when trying to load the module.
How to Handle Modules Loaded in VHost Files
Some modules are loaded in the main configuration file, while others are loaded in the virtual host (vhost) configuration files. You must check both locations to ensure you do not accidentally disable a module that is only needed for a specific site.
- Navigate to the vhost configuration directory as shown in the previous section.
- Open each
.conffile and search forLoadModulelines inside it. - If a module is only loaded in a vhost file, disabling it in the main configuration will not affect that site. You must edit the specific vhost file and comment out the
LoadModuleline there as well.
What to Do if You Disable the Wrong Module
If you disable a module that your site needs, the site will likely return an Internal Server Error or a blank page. You can quickly restore functionality by enabling the module again.
- Open the configuration file where you commented out the module.
- Remove the hash symbol (
#) from the beginning of the line. - Save the file and reload Apache with
sudo systemctl reload apache2orsudo systemctl reload httpd. - Refresh your browser to see if the site loads correctly.
Related
- NIDA Research Training Modules – How to Access and Use
- How to Declutter Your PC: A Step-by-Step Guide
- How to Declutter Your Seasonal Wardrobe
General information for everyday wellbeing, not medical advice. If something affects your health, sleep or mood for more than a short while, talk to a qualified professional. Read more
Spotted an error? Tell us and we will correct it (corrections policy).