Linux disable unneeded modules in Apache to save memory

Q. How do I disable unneeded Apache modules under Debian Linux?

A. You can disable all unneeded modules in Apache to save memory and improve performance. This may also result into improved security. Different Linux distribution follows different methods for disabling modules.

Debian / Ubuntu Linux disable a module

Debian / Ubuntu Linux comes with two scripts:
(a) a2enmod is a script that enables the specified module within the apache2 configuration. It does this by creating symlinks within /etc/apache2/mods-enabled.

(b) a2dismod disables a module by removing those symlinks. It is not an error to enable a module which is already enabled, or to disable one which is already disabled.

a2dismod {module-name}

For example disable a module called foo or mime_magic, enter:
# a2dismod foo
# a2dismod mime_magic

Enable a module again

If you ever need to re-enable disabled modules, use a2enmod command as follows:

a2enmod {module-name}

For example, enable imagemap module, enter:
# a2enmod imagemap

Note if don’t know module name, it will show a list of all available modules:
# a2enmod

Which module would you like to disable?
Your choices are: alias auth_basic authn_file authz_default authz_groupfile authz_host authz_user autoindex cgi dir env fastcgi mime negotiation php5 setenvif status userdir
Module name?  authz_user

CentOS / Redhat (RHEL) / Fedora Linux disable a module

Under Redhat based Linux distributions you need to modify *.conf file stored in /etc/httpd/conf.d/ directory. Apache scans for files with the .conf suffix at start up.

So if the system does not need to use mod_python, rename ‘python.conf’ to ‘python.bak’ and restart Apache with the command ‘service httpd restart in order to disable that particular module and save memory.
# cd /etc/httpd/conf.d/
# mv perl.conf no.perl.bak
# /etc/init.d/httpd restart

Enable a module

To re-enable modules, simply rename them to their original names and restart Apache to get back module functionality:
# cd /etc/httpd/conf.d/
# mv no.perl.bak perl.conf
# /etc/init.d/httpd restart

More about /etc/httpd/conf.d/ directory

This directory holds Apache 2.0 module-specific configuration files; any files in this directory which have the “.conf” extension will be processed as Apache configuration files. Files are processed in alphabetical order, so if using configuration directives which depend on, say, mod_perl being loaded, ensure that
these are placed in a filename later in the sort order than “perl.conf”.

  • manual.conf : This configuration file allows the manual to be accessed at http://localhost/manual/
  • perl.conf : mod_perl incorporates a Perl interpreter into the Apache web server, so that the Apache web server can directly execute Perl code.
  • php.conf : php5 module for php
  • proxy_ajp.conf : When loaded, the mod_proxy_ajp module adds support for proxying to an AJP/1.3 backend server such as Tomcat.
  • python.conf : mod_python is a module that embeds the Python language interpreter within the server, allowing Apache handlers to be written in Python.
  • squid.conf : Access to squid cache manager
  • ssl.conf : Apache SSL server configuration
  • webalizer.conf : Webalizer stats configuration
  • welcome.conf : This configuration file enables the default “Welcome” page if there is no default index page present for
    the root URL.

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

3 comments… add one
  • Darko Bunic Aug 1, 2008 @ 7:25

    You can disable even more modules from httpd.conf configuration file. Default apache setup loads DAV, Proxy, Speling, Ldap modules and they are needless for LAMP setup. I wrote more about it on
    Thanks you!

  • Darko Bunic Jun 24, 2009 @ 6:17

    Sorry, link to the LAMP setup is:

  • billy Dec 17, 2014 @ 21:51

    thank for information
    this rename will disable modules?

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.