← Back to Apache Course | Chapter 3: Modules | Lesson 5 of 5

Common Modules

Beyond rewrite/ssl/proxy/headers, Apache ships with dozens of other modules that add specific features -- this lesson is a tour of the ones you'll run into most often.

How Modules Work

Apache's core does relatively little on its own -- almost every feature, including ones that feel built-in, is actually a module loaded via LoadModule module_name modules/file.so. This design lets you keep a lean server by only loading what you actually use, and is why enabling a feature so often means "enable the module" as a first step.

mod_dir and mod_autoindex

mod_dir supplies the DirectoryIndex directive, which decides which filename (index.html, index.php, etc.) Apache serves automatically when a request names only a directory. mod_autoindex generates the automatic file listing you see when Options Indexes is on and no index file exists.

mod_deflate and mod_expires

mod_deflate compresses responses before sending them (covered in the Performance chapter). mod_expires generates Expires/Cache-Control headers automatically based on file type and age, an alternative to setting them by hand with mod_headers.

mod_php / PHP-FPM, and mod_wsgi

Historically, mod_php ran PHP directly inside the Apache process; modern setups more often run PHP-FPM as a separate process and connect to it via mod_proxy_fcgi, which scales and isolates better. mod_wsgi does the equivalent job for Python web apps, embedding a WSGI application (like Django or Flask) directly inside Apache as an alternative to proxying to Gunicorn.

Checking What's Loaded

apachectl -M (or apache2ctl -M on Debian/Ubuntu) lists every currently loaded module -- the quickest way to confirm whether the module a directive needs is actually active before spending time debugging the directive itself.

Note: Run apachectl -M | grep rewrite (swap in any module name) whenever a directive seems to be silently ignored -- it's often simply that the module backing it was never loaded.

Example: Listing loaded modules

apacheconf
apachectl -M

# Example output (truncated):
# core_module (static)
# rewrite_module (shared)
# ssl_module (shared)
# proxy_module (shared)
# headers_module (shared)
{# Flagged by hand after confirming a runner can't handle this example (a shell command / go.mod file stored as a TopicExample, a language feature the configured runner version doesn't support, or output that blows a runner's sandbox limit) -- see TopicExample.norun. Never render the run button for these, regardless of language, since it would just fail at execute_code (or worse, hang the Judge0 queue on a submission that can never finish cleanly). #}

⚠️ This example can't run in the browser editor. Try it in your own local environment instead.

{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Writing a directive that belongs to a specific module without checking that module is loaded first -- Apache may just ignore it, or refuse to start with an "invalid command" error.
  2. Still running the older mod_php model for a new setup, when PHP-FPM via mod_proxy_fcgi generally scales and isolates PHP processes better on modern Apache.
  3. Assuming every Apache feature is part of the "core" server, when the great majority of them -- including ones as basic as directory indexes -- are actually separate loadable modules.
Chapter Summary
  • mod_rewrite (URL rewriting), mod_ssl (HTTPS), mod_proxy (forwarding to a backend), and mod_headers (custom response headers) are the four modules almost every real Apache site relies on.
  • Apache's core is intentionally minimal, and nearly every feature -- directory indexes, compression, PHP/Python execution -- comes from a separate loadable module; apachectl -M shows what's currently active.
🔒

Chapter Quiz — Complete all 5 topics to unlock

0/5 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.