Apache Cheat Sheet

Apache HTTP Server remains one of the most widely used web servers in the world. This cheat sheet covers the most important commands, virtual hosts, SSL configuration, redirects, security hardening, troubleshooting and performance optimization.
Apache Service Commands
sudo systemctl start apache2sudo systemctl stop apache2sudo systemctl restart apache2sudo systemctl reload apache2sudo systemctl status apache2sudo systemctl enable apache2Configuration Validation
sudo apachectl configtestsudo apachectl -SImportant Apache Locations
/etc/apache2/apache2.conf
/etc/apache2/sites-available/
/etc/apache2/sites-enabled/
/var/log/apache2/access.log
/var/log/apache2/error.log
/etc/apache2/mods-available/
/etc/apache2/mods-enabled/Virtual Host Example
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html
<Directory /var/www/html>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>Enable Virtual Host
sudo a2ensite example.conf
sudo systemctl reload apache2SSL Certificate (Let's Encrypt)
sudo apt install certbot python3-certbot-apache -ysudo certbot --apache -d example.com -d www.example.comRedirect HTTP To HTTPS
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]Common .htaccess Rules
# Block Directory Listing
Options -Indexes
# Protect .env
<Files ".env">
Order allow,deny
Deny from all
</Files>Enable Required Modules
sudo a2enmod rewrite
sudo a2enmod ssl
sudo a2enmod headers
sudo a2enmod expires
sudo systemctl restart apache2Security Headers
Header always set X-Frame-Options SAMEORIGIN
Header always set X-Content-Type-Options nosniff
Header always set Referrer-Policy strict-originEnable Compression
sudo a2enmod deflate
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript
</IfModule>Browser Caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
</IfModule>Monitor Logs
tail -f /var/log/apache2/access.logtail -f /var/log/apache2/error.logTroubleshooting Commands
sudo apachectl configtestsudo journalctl -u apache2 -fcurl -I https://example.comnetstat -tulpn | grep :80netstat -tulpn | grep :443Frequently Asked Questions
What is Apache HTTP Server?
Apache HTTP Server is one of the world's most widely used web servers. It powers websites, web applications, APIs, content management systems and enterprise platforms.
Is Apache still relevant in 2026?
Yes. Apache remains extremely popular for WordPress, Laravel, PHP applications, enterprise hosting and shared hosting environments worldwide.
Apache vs Nginx: Which is better?
Apache offers excellent compatibility and flexibility, while Nginx generally performs better for high-concurrency workloads. Many hosting platforms use both together.
How do I restart Apache?
sudo systemctl restart apache2This command restarts the Apache service and reloads configuration changes.
How do I check Apache configuration errors?
sudo apachectl configtestThis command validates Apache configuration files and identifies syntax errors before restarting the service.
What is an Apache Virtual Host?
Virtual Hosts allow multiple websites to run on a single Apache server using separate domains and configurations.
How do I redirect HTTP to HTTPS?
Apache supports automatic HTTPS redirection using RewriteRule directives or virtual host configuration.
How do I install a free SSL certificate?
Let's Encrypt and Certbot provide free SSL certificates that can be automatically installed and renewed on Apache.
What are Apache security headers?
Security headers such as X-Frame-Options, X-Content-Type-Options and Referrer-Policy help protect websites against common attacks.
How do I view Apache logs?
tail -f /var/log/apache2/error.logApache logs are essential for troubleshooting website errors, SSL issues and performance problems.
How can I improve Apache performance?
Enable compression, browser caching, HTTP/2, keep-alive connections, optimized MPM settings and proper PHP integration.
Is Apache good for WordPress hosting?
Yes. Apache is one of the most commonly used web servers for WordPress and WooCommerce hosting environments.
Can Apache host Laravel applications?
Absolutely. Apache works very well with Laravel and other PHP frameworks when mod_rewrite and proper virtual host configurations are enabled.
What is the most common Apache issue?
The most common issues include incorrect virtual host configuration, SSL certificate problems, permission errors and rewrite rule conflicts.
Apache Optimization With CloudRevol
CloudRevol's AcceleronX Hosting Stack includes Apache tuning, compression, browser caching, SSL optimization, security hardening, database optimization and proactive monitoring.


