Beginner Fundamentals

How Apache Works

Apache uses a master process and several worker processes to handle traffic. Knowing this model helps you understand performance and configuration choices later.

Master and Workers

The master process starts as root, reads the configuration, and binds to the network ports. It then spawns worker processes (or threads) that actually handle incoming requests. The master never serves requests itself; it supervises the workers.

Multi-Processing Modules (MPM)

An MPM controls how Apache creates workers. There are three common options:

  • prefork: one process per connection, no threads. Very stable, uses more memory.
  • worker: multiple processes, each with many threads. Lower memory use.
  • event: like worker, but handles keep-alive connections more efficiently. The modern default.
# See which MPM is active
apache2ctl -V | grep -i mpm

Request Flow

A request travels through Apache in stages:

  1. Browser sends an HTTP request to a listening port.
  2. The master hands the connection to a free worker.
  3. Apache matches the request to a virtual host and directory.
  4. Modules process the request (rewrite, auth, etc.).
  5. Apache sends the response and logs it.

Understanding this flow makes the rest of the configuration easier to follow.