Blog about Web Programming and Electronics
💬 👤
back Back to blog
Linux

How to Install Apache or Nginx Web Server on Linux (Ubuntu / Debian)

A web server is the foundational software layer that receives incoming browser requests over HTTP and HTTPS, serving web pages, media assets, and API payloads. The two dominant solutions in the Linux ecosystem are Apache and Nginx. In this guide, we compare both architectures and provide step-by-step installation instructions for Ubuntu and Debian environments.

Architectural Comparison: Apache vs Nginx

While both servers deliver rock-solid reliability, they utilize different concurrency models and operational paradigms.

Feature Apache HTTP Server Nginx Web Server
Architecture Process/thread-driven (allocates threads per active connection). Asynchronous, event-driven (minimal RAM footprint under load).
Static Asset Handling Fast, but consumes higher memory resources per request. Extremely optimized for high-throughput static assets (images, CSS, JS).
Per-Directory Config Supports .htaccess overrides within directories. No per-directory files; all routing lives in centralized configs.
Common Use Cases Shared web hosting (cPanel), LAMP stacks, WordPress. High-traffic portals, Reverse Proxy, Microservices, Docker.

Installing the Apache Web Server

Deploy Apache on Debian and Ubuntu distributions using the standard apt package manager.

# 1. Update package repository indexes and install Apache
sudo apt update
sudo apt install apache2 -y

# 2. Allow HTTP/HTTPS traffic through the UFW firewall
sudo ufw allow 'Apache Full'

# 3. Verify running service status
sudo systemctl status apache2

Installing the Nginx Web Server

If you require a lightweight, event-driven architecture or reverse proxy capabilities, deploy Nginx.

# 1. Update package repository indexes and install Nginx
sudo apt update
sudo apt install nginx -y

# 2. Allow HTTP/HTTPS traffic through the UFW firewall
sudo ufw allow 'Nginx Full'

# 3. Verify running service status
sudo systemctl status nginx

Where to Deploy Web Assets

By default, both web servers use /var/www/html/ as the root document directory. Placing an index.html or index.php file inside this folder makes it immediately accessible when navigating to your server's IP address (e.g., http://your_server_ip/) in any web browser.

back Back to blog