Apache HTTP Server: Fundamentals & Core Configuration
Apache HTTP Server is the world's most widely deployed web server. It's a module-based server that handles everything from static file serving to proxying, SSL termination, and URL rewriting.
Apache vs Nginx
Apache: process/thread per connection (event MPM is more efficient), .htaccess per-directory config, rich module ecosystem, battle-tested — good for shared hosting, dynamic content via mod_php
Nginx: event-driven async architecture, no .htaccess (config reload needed), excellent static file serving, better at high concurrency — preferred for modern deployments
Practical choice: Nginx as reverse proxy → Apache as backend is a common combo
Installation
# Debian/Ubuntu
sudo apt update && sudo apt install apache2
sudo systemctl enable --now apache2
# RHEL/CentOS/Amazon Linux
sudo dnf install httpd
sudo systemctl enable --now httpd
# macOS (via Homebrew)
brew install httpd
brew services start httpdMPM (Multi-Processing Module)
prefork: one process per request, no threading, compatible with non-thread-safe libs (older mod_php). High memory use.
worker: multi-process + multi-threaded. More concurrent connections with less memory.
event: like worker but keeps connections alive without tying up threads. Best for modern workloads. Default on Ubuntu.
# Check active MPM
apache2ctl -V | grep MPM
httpd -V | grep MPM
# Switch MPM (Ubuntu)
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event
sudo systemctl restart apache2Key Configuration Files
# Ubuntu/Debian paths
/etc/apache2/apache2.conf # Main config
/etc/apache2/ports.conf # Listen directives
/etc/apache2/sites-available/ # Virtual host configs (enable with a2ensite)
/etc/apache2/sites-enabled/ # Symlinks to active sites
/etc/apache2/mods-available/ # Available modules
/etc/apache2/mods-enabled/ # Enabled modules (symlinks)
/var/log/apache2/access.log # Access log
/var/log/apache2/error.log # Error log
# RHEL/CentOS paths
/etc/httpd/conf/httpd.conf # Main config
/etc/httpd/conf.d/ # Additional configs
/var/log/httpd/access_log
/var/log/httpd/error_logCore Directives
# apache.conf / httpd.conf key settings
ServerName www.example.com
ServerAdmin webmaster@example.com
# Document root for default site
DocumentRoot /var/www/html
# Directory permissions
<Directory /var/www/html>
Options -Indexes +FollowSymLinks # Disable directory listing
AllowOverride All # Allow .htaccess (use None for performance)
Require all granted
</Directory>
# Logging
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# Log format definition
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
# Keep-Alive
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
# Listen on ports
Listen 80
Listen 443apachectl Commands
# Start / stop / restart
sudo apachectl start
sudo apachectl stop
sudo apachectl restart # Full restart (brief downtime)
sudo apachectl graceful # Reload config, finish active connections first
sudo apachectl graceful-stop
# Validate config before restarting
sudo apachectl configtest
sudo apachectl -t # Same thing
# Show compiled-in settings
apache2ctl -V
# List loaded modules
apache2ctl -Mmod_status — Server Status
# Enable mod_status
LoadModule status_module modules/mod_status.so
<Location /server-status>
SetHandler server-status
Require ip 127.0.0.1 10.0.0.0/8 # Restrict access
</Location>
ExtendedStatus On # Include per-request details# Enable on Ubuntu
sudo a2enmod status
curl http://localhost/server-status?auto # Machine-readable outputKeep your own version of these notes — editable, searchable, and organised by your stack.
Start free