Linux VPS

Apache modules: list, enable and disable them safely

How Apache's modular design works, the modules a modern server needs, how to enable or disable them on Debian/Ubuntu and AlmaLinux, and how trimming modules saves memory.

IntermediateLinux VPS2 min read

Almost every Apache feature, from rewriting URLs to TLS, is a separately loaded Apache module. Loading only what you use keeps the attack surface small and lowers memory per process. This guide shows how to see which modules are active and how to enable or disable them on both major Linux families.

Before you start

  • Apache 2.4 on a VPS with root access.
  • On cPanel servers modules are managed with EasyApache 4 in WHM, not by hand.

List loaded Apache modules

apachectl -M

Output marks each as (static) (compiled in) or (shared) (loaded from a .so file). Only shared modules can be toggled.

Enable and disable on Debian/Ubuntu

Modules live in /etc/apache2/mods-available/; enabled ones are symlinked into mods-enabled/.

  • Enable: sudo a2enmod rewrite headers
  • Disable: sudo a2dismod status autoindex
  • Check one: a2query -m rewrite

Then validate and restart:

sudo apachectl configtest && sudo systemctl restart apache2

The same pattern exists for config snippets (a2enconf/a2disconf) and sites (a2ensite/a2dissite).

Enable and disable on AlmaLinux/Rocky

Modules are loaded by LoadModule lines in /etc/httpd/conf.modules.d/*.conf.

  1. Find the line: grep -r autoindex /etc/httpd/conf.modules.d/.
  2. Comment it out with # to disable, or uncomment to enable.
  3. Extra modules usually come as packages: sudo dnf install mod_ssl, mod_security, mod_http2.
  4. Run sudo apachectl configtest && sudo systemctl restart httpd.

Modules a modern server needs

ModulePurpose
mpm_eventConcurrency model (see Apache MPMs)
sslHTTPS
http2HTTP/2 (Protocols h2 http/1.1)
rewriteURL rewriting and redirects
headersSecurity and cache headers
proxy, proxy_fcgiPass PHP to PHP-FPM
setenvif, mime, dir, aliasCore request handling
deflate, brotliCompression
expiresBrowser caching
remoteipReal client IP behind a proxy or CDN
reqtimeoutSlowloris protection

Modules you can often remove

  • autoindex: directory listings. Disable unless you need them.
  • status / info: useful, but expose server details; keep only if restricted to localhost.
  • cgi, cgid: only for legacy CGI scripts.
  • userdir: /~user/ URLs, rarely wanted.
  • dav, dav_fs: WebDAV, only if used.
  • php (mod_php): replace with PHP-FPM to use the event MPM.

Check a module's directives are guarded

Wrap module-specific config in <IfModule mod_headers.c> so Apache still starts if the module is ever disabled. Without the guard, a disabled module makes Apache refuse to start with "Invalid command".

Troubleshooting

  • "Invalid command 'RewriteEngine'": mod_rewrite is not loaded. Enable it.
  • "Module xyz is already loaded, skipping": two files load it. Remove the duplicate LoadModule.
  • Apache won't start after disabling a module: run apachectl configtest; it names the file and line using it.

FAQ: Apache modules

Does a2enmod restart Apache?

No. It only creates the symlink; restart or reload yourself.

Is reload enough after enabling a module?

A graceful restart (apachectl graceful) loads new modules without dropping connections.

Does LiteSpeed use Apache modules?

No. LiteSpeed implements the common directives itself and ignores Apache module files.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.