How to Install Apache on Ubuntu & Debian (Complete Guide)

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

PathPurpose
/etc/apache2/apache2.confMain 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 configtest before 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)
  • apache, install apache, web server, ubuntu, debian
  • 0 Los Usuarios han Encontrado Esto Útil
¿Fue útil la respuesta?

Artículos Relacionados

How to Install Nginx on Ubuntu & Debian (Complete Guide)

Nginx is one of the world's most widely used web servers, known for its speed, low resource...

Nginx Virtual Hosts (Server Blocks): Hosting Multiple Websites on One VPS

Nginx "server blocks" (the equivalent of Apache's virtual hosts) let you host multiple...

Apache Virtual Hosts: Hosting Multiple Websites on One VPS

Apache Virtual Hosts allow a single server to host multiple independent websites, each identified...

How to Configure Nginx as a Reverse Proxy for Node.js/Docker Apps

A reverse proxy sits in front of your application, handling incoming traffic on standard ports...

How to Install OpenLiteSpeed on a Linux VPS

OpenLiteSpeed is a high-performance, open-source web server known for excellent PHP performance...