1. INSTALLATION COMMANDS
# Ubuntu/Debian sudo apt update && sudo apt install apache2 apache2-utils # CentOS/RHEL/Fedora sudo yum install httpd httpd-tools # or dnf # Enable at boot & start sudo systemctl enable apache2 # or httpd sudo systemctl start apache2
2. BASIC SITE CONFIG
# /etc/apache2/sites-available/mysite.conf
<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/mysite
<Directory /var/www/mysite>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/mysite-error.log
CustomLog ${APACHE_LOG_DIR}/mysite-access.log combined
</VirtualHost>
3. ENABLE SITE COMMANDS
# Ubuntu/Debian sudo a2ensite mysite.conf sudo systemctl reload apache2 # CentOS/RHEL (just copy to conf.d) sudo cp mysite.conf /etc/httpd/conf.d/ sudo systemctl reload httpd
4. CUSTOM ERROR PAGES — MINIMAL CONFIG
Option A: Global (in virtual host)
<VirtualHost *:80>
# ... other config ...
# Point to your custom error pages directory
ErrorDocument 400 /errors/400.html
ErrorDocument 401 /errors/401.html
ErrorDocument 403 /errors/403.html
ErrorDocument 404 /errors/404.html
ErrorDocument 500 /errors/500.html
ErrorDocument 502 /errors/502.html
ErrorDocument 503 /errors/503.html
ErrorDocument 504 /errors/504.html
</VirtualHost>
Option B: Directory-based (in .htaccess)
# .htaccess in your site root ErrorDocument 404 /404.html ErrorDocument 500 /500.html
Option C: Complete error handling config
<VirtualHost *:80>
# ... other config ...
# Custom error docs
Alias /errors "/var/www/mysite/errors"
ErrorDocument 404 /errors/404.html
ErrorDocument 500 /errors/500.html
# Make error pages accessible
<Directory "/var/www/mysite/errors">
Require all granted
Options -Indexes
</Directory>
</VirtualHost>
5. MAINTENANCE MODE CONFIG
# /etc/apache2/sites-available/maintenance.conf
<VirtualHost *:80>
ServerName mysite.com
DocumentRoot /var/www/maintenance
# Allow only specific IPs
<Directory /var/www/maintenance>
Order deny,allow
Deny from all
Allow from 192.168.1.0/24 # Your office IP
Allow from 10.0.0.0/8 # Your VPN
ErrorDocument 403 /maintenance.html
</Directory>
ErrorDocument 503 /maintenance.html
</VirtualHost>
6. TESTING ERROR PAGES
# Quick curl tests curl -I http://mysite.com/nonexistent-page # Should show 404 curl -I http://mysite.com/server-error # If you have error generator # Check Apache config sudo apache2ctl configtest # Test specific error sudo tail -f /var/log/apache2/error.log
7. ONE-LINER ERROR PAGE SETUP
# Create basic error pages directory mkdir -p /var/www/mysite/errors echo "404 - Not Found" > /var/www/mysite/errors/404.html echo "500 - Server Error" > /var/www/mysite/errors/500.html # Add to Apache config echo 'ErrorDocument 404 /errors/404.html' >> /etc/apache2/sites-available/mysite.conf echo 'ErrorDocument 500 /errors/500.html' >> /etc/apache2/sites-available/mysite.conf # Reload sudo systemctl reload apache2
8. BONUS: REVERSE PROXY ERROR PAGES
<VirtualHost *:80>
ProxyPass / http://backend:3000/
ProxyPassReverse / http://backend:3000/
# Handle backend errors
ProxyErrorOverride On
ErrorDocument 502 /errors/502.html
ErrorDocument 503 /errors/503.html
ErrorDocument 504 /errors/504.html
</VirtualHost>
That’s it — just the configs, no fluff. Enable, reload, test.