Apache HTTP Server

A modular web server with virtual hosts, configurable MPMs, directory-level rules, and reverse-proxy support.

8 min read 7 lesson sections
  • #http
  • #web server
  • #virtual hosts
  • #modules
  • #mpm
  • #.htaccess
  • #php-fpm
  • #reverse proxy
Apache HTTP Server: A modular web server with virtual hosts, configurable MPMs, directory-level rules, and reverse-proxy support.
Concept map

Apache HTTP Server, usually called Apache or httpd, is a web server that accepts HTTP or HTTPS requests and decides how to answer them. It can return a file from disk, apply a configured rule, or pass a request to an application service. It is not the application itself and does not replace the runtime used by PHP, Java, or ASP.NET Core.

What happens to a request?

Apache accepts a connection on a configured address and port, selects a virtual host using the request’s host name and port, then processes the matching rules. The response may be a static file, a redirect, or a request forwarded to an application.

Browser ──> Apache ──> static file
Browser ──> Apache ──> PHP-FPM or another application service

One Apache installation can serve several domains. Each virtual host can define its own host name, document root, TLS settings, logs, and routing rules.

MPM: how Apache handles work

Apache uses a Multi-Processing Module (MPM) to organize its worker processes and threads. Common choices include:

  • Prefork uses separate processes and is useful for some older or process-specific module setups.
  • Worker combines processes and threads to handle requests.
  • Event builds on the worker model and can free worker threads from waiting on idle keep-alive connections.

The available MPM and compatible modules depend on the Apache package and configuration. The event MPM can handle concurrent traffic efficiently; Apache should not be assumed slow just because it has a process-and-thread model. Measure the actual application and workload.

How a connection becomes a response

The MPM decides how Apache distributes work across processes and threads; it does not determine the response by itself. After accepting a connection, Apache selects a virtual host and passes the request through configured processing stages until a handler can answer it:

HTTP/HTTPS connection
       ↓
Listening address and port
       ↓
Virtual host selection by address, port, and host name
       ↓
Authentication, access rules, rewrite, or proxy handling
       ↓
Static file or backend application
       ↓
HTTP response and request log

Keep-Alive allows a connection to be reused for later requests. The number of open connections is therefore not the same as the number of requests being processed at one moment; this distinction matters when tuning timeouts and resources.

Modules, configuration, and .htaccess

Apache’s module system provides features such as TLS, URL rewriting, authentication, and proxying. Enable only the modules the site needs, and test configuration changes before reloading the service.

Modules participate in request processing to add or change behavior: mod_ssl handles TLS, mod_rewrite handles URL rules, and mod_proxy forwards requests. Modules may depend on one another, and a module can have MPM compatibility requirements. Check the installed package’s documentation rather than copying a generic module list.

Apache can read .htaccess files in site directories when the server configuration allows overrides. This lets a site keep some rewrite or access rules alongside its files, but it also means configuration can be spread across directories. For centralized administration, keep rules in the main server configuration where practical.

.htaccess rules are limited by the server’s AllowOverride setting; they cannot override every main-server directive. When a rule has no effect, check parent-directory settings, AllowOverride, required modules, and the exact URL path before changing unrelated configuration.

Nginx does not read .htaccess. When moving a site from Apache to Nginx, review its rewrite, access, and directory rules and translate the required behavior into Nginx’s central configuration.

Connecting PHP and other applications

Apache can serve static files directly. A PHP site may use PHP-FPM, or a supported PHP module depending on the deployment. Other application runtimes can listen on an internal address while Apache acts as a reverse proxy.

For example, the following simplified virtual host forwards requests to an application listening locally on port 5000. It requires the appropriate Apache proxy modules; public TLS configuration is intentionally omitted:

<VirtualHost *:80>
    ServerName app.example.test

    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:5000/
    ProxyPassReverse / http://127.0.0.1:5000/
</VirtualHost>

ASP.NET Core normally runs on Kestrel, and PHP commonly runs through PHP-FPM; Apache can sit in front of either. The application still needs correct forwarded-header and trusted-proxy settings.

Distinguishing files from applications

For a file under DocumentRoot, Apache can serve it after applying access rules and content-type handling. A request such as /orders/42 may instead need application logic; Apache then forwards it rather than treating it as a file. PHP deployments commonly pass requests to PHP-FPM over FastCGI, while HTTP applications such as Kestrel use reverse-proxy configuration.

Do not expose application source or secrets as public web content. Point DocumentRoot at the intended public directory, and review access to hidden files and backups. For PHP, make sure the handler does not send nonexistent scripts to PHP-FPM.

Virtual hosts and configuration layers

Configuration can be divided into server-wide settings, per-VirtualHost settings, and rules for particular paths or directories. ServerName and ServerAlias identify a site’s names; DocumentRoot sets the starting directory for its files. <Directory> controls access and options for a filesystem path, which is different from matching a URL.

If a request’s host name does not match a virtual host configured for its address and port, Apache uses the default virtual host for that address and port. A typo in ServerName or an unexpected definition order can therefore show the wrong site even though the server is running. Inspect the loaded virtual hosts when diagnosing this behavior.

TLS and caching

Apache can terminate public TLS and forward requests internally to an application, depending on the deployment design. The site name must match its certificate, and HTTPS redirects should be tested before they are enabled. Caching is not a substitute for application logic: do not place personalized or authenticated responses in a shared cache unless user isolation and invalidation are designed correctly.

When Apache is a good fit

Apache is a practical choice when an existing application relies on .htaccess, when the required Apache modules are already part of the deployment, or when the team already operates Apache reliably. Nginx may fit better when the deployment calls for centralized routing or a dedicated front proxy. Neither choice guarantees better performance for every site.

If you are comparing both before a migration, use the Apache HTTP Server vs Nginx comparison. Benchmark the same application and traffic pattern, and compare latency, throughput, CPU, memory, and errors before changing production.

Operate it carefully

Keep the configuration under change control, validate it with the test command provided by the installed Apache package, and review access and error logs after changes. Use HTTPS for public traffic, restrict access to internal services, and practice configuration changes in a development environment before applying them to a production host.

Many Linux distributions provide commands such as apachectl configtest to check syntax, apachectl -S to show virtual hosts, and apachectl -M to list loaded modules; names vary by operating system and package. A syntax check cannot prove the backend application is healthy, so monitor Apache and the backend service together.

When a request fails, separate the layers: did it reach the expected virtual host? Can the directory rules read the file? Does a rewrite send it to the intended path? If it is proxied, is the backend listening on the configured address and port? This layered diagnosis is more useful than changing the MPM or increasing timeouts without evidence.

Measuring Apache performance

Test static files separately from requests that execute in the application. Keep traffic, TLS, and Keep-Alive settings consistent, and record request rate, 95th- and 99th-percentile latency, CPU, memory, and errors. If the backend or database is the bottleneck, changing the web server alone will not fix it.

Official references