Common Modules
In this page:
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.
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
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). #}
- 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.
- 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.
- 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.
- 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 -Mshows what's currently active.
Chapter Quiz — Complete all 5 topics to unlock
0/5 topics done
Complete these topics first: