Apache HTTP Server is one of the most widely used web servers, valued for its stability, flexible module system, and strong compatibility with PHP-based applications like WordPress.
Prerequisites
- Ubuntu 22.04/24.04 or Debian 11/12 VPS
- Root or sudo access
Step 1 — Update the System
sudo apt update
sudo apt upgrade -y
Step 2 — Install Apache
sudo apt install apache2 -y
Step 3 — Enable and Start Apache
sudo systemctl enable apache2
sudo systemctl start apache2
sudo systemctl status apache2
Step 4 — Allow HTTP/HTTPS Through the Firewall
sudo ufw allow 'Apache Full'
Step 5 — Test in a Browser
http://YOUR_SERVER_IP
You should see the default Apache2 Ubuntu/Debian welcome page.
Key File Locations
| Path | Purpose |
|---|---|
/etc/apache2/apache2.conf | Main configuration file |
/etc/apache2/sites-available/ | Virtual host definitions |
/etc/apache2/sites-enabled/ | Active sites |
/var/www/html/ | Default document root |
/var/log/apache2/ | Access and error logs |
Essential Apache Commands
sudo systemctl restart apache2
sudo systemctl reload apache2
sudo apache2ctl configtest
sudo journalctl -u apache2
Enabling Modules
Apache's functionality is extended through modules. To enable URL rewriting (required by many PHP apps, including WordPress):
sudo a2enmod rewrite
sudo systemctl restart apache2
Adding PHP Support
sudo apt install php libapache2-mod-php -y
sudo systemctl restart apache2
Common Errors
Port 80 already in use — typically Nginx already running:
sudo ss -tulpn | grep :80
403 Forbidden — check document root ownership and permissions:
sudo chown -R www-data:www-data /var/www/yoursite
Syntax error after editing config — always validate before restarting:
sudo apache2ctl configtest
Best Practices
- Always run
apache2ctl configtestbefore restarting - Disable unused modules to reduce attack surface
- Enable HTTPS for every production site
FAQ
Apache or Nginx — which should I choose?
Apache offers deep module flexibility and excellent PHP integration via .htaccess; Nginx generally handles high concurrency with lower resource usage. Both are production-proven.
Related Articles
- Apache Virtual Hosts: Hosting Multiple Websites
- How to Install Let's Encrypt SSL with Certbot (Nginx & Apache)
- How to Fix Common Apache Errors (500/403/AH Errors)
