Loading...

Lab 81: Setting Up a Web Server

Deploy a basic Apache HTTP server and publish a static landing page on port 80. Verify the unit is healthy, confirm the daemon is listening, then prove end-to-end delivery with a local HTTP request.

services web core

Scenario

You need to deploy a basic Apache HTTP web server to serve a static landing page over port 80. Your job is to install the package, enable and start the service, publish a custom index.html into the default web root, then validate the response with a local HTTP request.

Operator context

This is the standard “get it online safely” workflow: install, enable, verify status, publish content, then prove it’s reachable with a simple client check before you add TLS, virtual hosts, or firewall rules.

Objective

  • Install Apache (httpd/apache2) with the system package manager.
  • Enable and start the web server service with systemd.
  • Publish a custom /var/www/html/index.html.
  • Confirm the server responds locally using curl.

Concepts

  • Apache’s service unit name differs by distro: httpd on RHEL-family, apache2 on Debian/Ubuntu.
  • The default document root is commonly /var/www/html, but distro configs can override it.
  • Verification means: unit is active, port is listening, and an HTTP request returns your expected content.

Walkthrough

Step 1 : Install the Apache web server package.
Note

Use the native package manager for your distro. On RHEL-family systems, prefer dnf over legacy yum.

Commands
# RHEL / CentOS / Fedora
sudo dnf install -y httpd

# Debian/Ubuntu
sudo apt update
sudo apt install -y apache2

# Arch
sudo pacman -S apache

Installing Apache provides the server binaries, default configuration, and a systemd service unit. Next you will start the service and publish content.

# Example result (varies by distro):
# httpd/apache2 installed successfully.
Step 2 : Enable and start the Apache service.
Commands
# RHEL-family unit name:
sudo systemctl enable --now httpd

# Debian/Ubuntu unit name:
sudo systemctl enable --now apache2

enable --now starts the service immediately and ensures it returns after reboot.

# Quick check:
systemctl status httpd --no-pager
# or
systemctl status apache2 --no-pager
Step 3 : Confirm Apache is listening on port 80.
Command
sudo ss -lntp | grep -E ':\b80\b' || true

This verifies the daemon is actually bound to the HTTP port. If you see no output, confirm the service is active and review unit logs.

# Example:
LISTEN 0 511 0.0.0.0:80 ... httpd
Step 4 : Publish a custom landing page.
Command
echo 'Hello from exit_0 (Lab 81)!' | sudo tee /var/www/html/index.html

Writing to /var/www/html requires elevated privileges. Using tee is a clean way to write as root without opening an editor.

# Confirm file exists:
sudo cat /var/www/html/index.html
Step 5 : Validate end-to-end HTTP response locally.
Commands
curl -s http://localhost
curl -I http://localhost

The first command proves content delivery. The second confirms you are getting a normal HTTP response (status, server, content type).

Hello from exit_0 (Lab 81)!
HTTP/1.1 200 OK

Breakpoints

service won’t start

Confirm the correct unit name for your distro (httpd vs apache2) and inspect logs with journalctl -u <unit>.

curl returns connection refused

Check the daemon is listening on port 80 (ss -lntp). If it’s not, re-check the unit state and recent log output.

wrong page is displayed

Confirm the document root is /var/www/html for your build, and verify your file contents. Some distros use different defaults or ship a default index page from another path.

Cleanup checklist

If you want to revert to a clean state, stop/disable the service and remove the package using your distro’s package manager.

Commands
# Stop/disable
sudo systemctl disable --now httpd 2>/dev/null || true
sudo systemctl disable --now apache2 2>/dev/null || true

# Remove the custom page
sudo rm -f /var/www/html/index.html

Reference

  • dnf install httpd: Install Apache on RHEL-family systems.
  • apt install apache2: Install Apache on Debian/Ubuntu systems.
  • pacman -S apache: Install Apache on Arch.
  • systemctl enable --now <unit>: Enable at boot and start immediately.
    • httpd: Unit name on RHEL-family systems.
    • apache2: Unit name on Debian/Ubuntu systems.
  • ss -lntp: Show listening TCP sockets and owning processes.
    • -l: listening sockets
    • -n: numeric output
    • -t: TCP sockets
    • -p: process info
  • /var/www/html: Common default Apache document root.
  • tee: Write to privileged paths cleanly when used with sudo.
  • curl http://localhost: Validate a local HTTP response.
    • -I: fetch headers only
    • -s: silent mode
  • journalctl -u <unit>: View service logs for troubleshooting.
    • -n 50: last 50 lines
    • --no-pager: print directly