Build Your Own Home Server

A step-by-step interactive guide to hosting your website from your living room using Apache on Linux

Prep
Apache
Files
Firewall
Network
Router
DNS
HTTPS
Progress: 0/8 steps completed
0
Before You Start
What we are building and what you need
The Journey of Every Web Request
User Types URL Browser DNS Router Your Server Page Loads

What is a home server?

A server is just a computer that provides a service to other computers. Your home server will run a program called Apache that listens for requests and sends back your website files. It is not special hardware — it is a normal computer running server software.

What You Need
  • A computer with Linux installed
  • Internet connection (Ethernet preferred)
  • Access to your router's admin panel
  • About 1 hour
What You Will Have
  • A live website on the internet
  • Your own domain name (free)
  • Encrypted HTTPS connection
  • Full control over your site
1
Prepare Your Linux Machine
Know your address and update your system

Why this matters

Your server needs a consistent local IP address so your router always knows where to send traffic. We also update the system so we install current, secure software.

Step 1A: Find your local IP address

Open a terminal on your Linux machine and run:

ip addr show
  • Look for the inet line under your network adapter (usually eth0 for wired, wlan0 for wireless)
  • It will look like 192.168.1.50 or 192.168.0.45
  • Write this number down. We need it for the router later.

Step 1B: Update your system

sudo apt update && sudo apt upgrade -y
  • apt update refreshes the list of available software
  • apt upgrade installs the latest versions
  • -y automatically answers "yes" to prompts
  • This may take 5–10 minutes if your system is outdated

⚠️ Stuck here?

If sudo asks for a password, type your user password (characters won't show on screen). If you get "command not found," make sure you are on a Debian/Ubuntu-based system. For other Linux distributions, the package manager will be different (e.g., dnf for Fedora).

2
Install Apache
The software that serves your website

What is Apache?

Apache HTTP Server is a program that runs in the background, listens for incoming requests on port 80, finds the right file on your computer, and sends it back to the visitor's browser. It is one of the most widely used web servers in the world.

Install Apache

sudo apt install apache2 -y
  • This downloads and installs Apache and its dependencies
  • After installation, Apache starts automatically
  • It is now listening on port 80 inside your machine

Verify Apache is running

sudo systemctl status apache2
  • Look for active (running) in green
  • systemctl is the command Linux uses to manage background services
  • If it says inactive, run: sudo systemctl start apache2

Test locally

curl http://localhost
  • curl is a command-line tool that fetches web pages
  • You should see HTML output — the Apache default page
  • This confirms Apache is answering requests from the same machine
3
Create Your Website
Replace the default page with your own content

Where do website files live?

Apache's default web root (the folder it looks in for files) is /var/www/html/. When someone visits your site, Apache looks for index.html in that folder and sends it.

Remove the placeholder

sudo rm /var/www/html/index.html

Create your own homepage

sudo nano /var/www/html/index.html
  • nano is a simple text editor inside the terminal
  • Since /var/www/html/ is a system folder, you need sudo to write to it

Type this inside nano:

<!DOCTYPE html> <html> <head> <title>My Home Server</title> </head> <body> <h1>This site is served from my living room</h1> <p>Built with Apache on Linux.</p> </body> </html>
  • Press Ctrl+O to save (then press Enter to confirm)
  • Press Ctrl+X to exit nano

Test from another device on your Wi-Fi

On your phone or another computer connected to the same network, open a browser and go to:

http://192.168.1.50

(Replace with your actual local IP from Step 1)

What just happened?

Your other device asked your Linux machine for a web page. Apache received the request, found index.html, and sent it back. This works only inside your home right now. The internet cannot reach it yet.

4
Configure the Firewall
Let Apache through the Linux firewall

What is a firewall?

Your Linux machine has a built-in gatekeeper called UFW (Uncomplicated Firewall). By default, it may block incoming requests. We need to tell it: "Allow web traffic on ports 80 and 443."

Check if the firewall is active

sudo ufw status
  • If it says Status: inactive, the firewall is not running. You can skip to the next step, but enabling it is recommended.
  • If it says Status: active, continue below.

Allow Apache through the firewall

sudo ufw allow 'Apache Full'
  • 'Apache Full' is a pre-built profile that opens both port 80 (HTTP) and port 443 (HTTPS)
  • UFW knows which ports Apache needs, so you don't have to memorize the numbers yet

Enable the firewall (if it was off)

sudo ufw enable
  • Type y and press Enter when it warns you about disrupting connections
  • SSH (port 22) is usually already allowed if you are connected remotely

Verify the rules

sudo ufw status

You should see rules for Apache Full, and possibly SSH.

5
Find Your Public IP
The address the internet sees

Two different addresses

You have a local IP (like 192.168.1.50) that only works inside your house. Your router has a public IP that the entire internet sees. When someone visits your site from another city, they use your public IP.

Get your public IP

curl ifconfig.me
  • This asks an external service to tell you what IP address it sees from your connection
  • It will look different from your local IP — something like 203.0.113.45
  • Write this number down.

Important: Your public IP changes

Most home internet plans give you a dynamic IP — it changes periodically. That is why we will set up Dynamic DNS in Step 7. But for now, we just need to know what it is today.

6
Port Forwarding on Your Router
The most critical step — open the door from the internet

What is port forwarding?

Your router is the gatekeeper. It has one public IP, but many devices inside your home. When a request from the internet arrives on port 80, the router needs a rule that says: "Send this to the Linux server at 192.168.1.50." Without this rule, the request dies at the router.

Log into your router

  • Open a browser and go to http://192.168.1.1 or http://192.168.0.1
  • If neither works, check the sticker on your router for the admin IP
  • Enter the admin username and password (also on the sticker, or set by you)

Find the Port Forwarding section

Look for one of these names in your router menu:

Port Forwarding
Virtual Servers
NAT / Gaming
Applications

Create two forwarding rules

Name External Port Internal IP Internal Port Protocol
Apache-HTTP 80 192.168.1.50 80 TCP
Apache-HTTPS 443 192.168.1.50 443 TCP

Replace 192.168.1.50 with your actual local IP from Step 1.

  • External Port: The port the internet sees (80 for HTTP, 443 for HTTPS)
  • Internal IP: Your Linux machine's local address
  • Internal Port: Same as external port (80 and 443)
  • Protocol: TCP — the standard for web traffic
  • Save or Apply the rules. Some routers require a reboot.

Test from outside your network

Use your phone with Wi-Fi turned OFF (use cellular data) or ask a friend:

http://YOUR_PUBLIC_IP

Replace with your actual public IP from Step 5.

If you see your page, the chain is complete

Internet → Public IP → Router → Port Forward → Linux → Apache → Your File. Every link works.

⚠️ It doesn't work?

  • Double-check the local IP — did it change? Set a static IP or DHCP reservation in your router.
  • Check your ISP — some block port 80. Try port 8080 externally and forward to 80 internally.
  • Firewall on router? Some routers have a separate firewall. Look for "SPI Firewall" or "Access Restrictions."
  • Wrong protocol? Some routers require you to select TCP/UDP. Choose TCP only.
7
Dynamic DNS
Give your server a name that never changes

The problem with IP addresses

Your public IP changes. If you give someone your IP today, it might be wrong tomorrow. Dynamic DNS gives you a free domain name (like yourname.duckdns.org) that automatically updates to point to your current IP.

Step 7A: Sign up at DuckDNS

  • Go to duckdns.org
  • Sign in with Google, GitHub, or Reddit
  • Create a subdomain: yourname.duckdns.org
  • Copy your token (a long string of letters and numbers)

Step 7B: Create the update script

mkdir ~/duckdns && cd ~/duckdns
nano duck.sh

Type this inside nano (replace YOURNAME and YOUR_TOKEN):

echo url="https://www.duckdns.org/update?domains=YOURNAME&token=YOUR_TOKEN&ip=" | curl -k -o ~/duckdns/duck.log -K -
  • Press Ctrl+O, then Enter, then Ctrl+X

Step 7C: Make it executable and test

chmod 700 duck.sh ./duck.sh cat duck.log
  • chmod 700 makes the script runnable by only you
  • ./duck.sh runs it
  • cat duck.log shows the result — it should say OK

Step 7D: Automate it

crontab -e
  • If it asks which editor to use, choose nano (option 1)
  • Add this line at the bottom:
*/5 * * * * ~/duckdns/duck.sh >/dev/null 2>&1
  • This means: "Run the script every 5 minutes, silently."
  • Press Ctrl+O, Enter, Ctrl+X

Test your domain

Wait 2–3 minutes, then visit:

http://yourname.duckdns.org

Replace with your actual DuckDNS subdomain.

8
Add HTTPS with Let's Encrypt
Encrypt your connection for free

HTTP vs. HTTPS

Port 80 — HTTPPort 443 — HTTPS
SecurityUnencryptedEncrypted (TLS/SSL)
DataReadable by anyone interceptingPrivate between browser & server
BrowserNo padlockShows padlock icon
Required forTesting onlyLogins, payments, SEO, production

Install Certbot

sudo apt install certbot python3-certbot-apache -y
  • certbot is the tool that gets free certificates from Let's Encrypt
  • python3-certbot-apache is the plugin that configures Apache automatically

Get the certificate

sudo certbot --apache -d yourname.duckdns.org
  • Replace yourname.duckdns.org with your actual DuckDNS domain
  • Enter your email when prompted (for renewal notices)
  • Agree to the terms
  • Choose whether to share your email (optional)
  • When asked about redirecting HTTP to HTTPS, choose 2: Redirect

What Certbot does automatically

  • Proves you own the domain by connecting to it
  • Downloads an SSL certificate
  • Configures Apache to use the certificate on port 443
  • Sets up automatic renewal (certificates expire every 90 days)
  • Creates an HTTP→HTTPS redirect

Verify HTTPS

Visit your site with https://:

https://yourname.duckdns.org
  • You should see a padlock icon in the browser address bar
  • Clicking the padlock should say "Connection is secure"
  • HTTP requests should automatically redirect to HTTPS

Test automatic renewal

sudo certbot renew --dry-run
  • This simulates renewal without actually changing anything
  • If it says success, you are set for life — Certbot handles the rest
You Did It
Your website is live on the internet from your home

You now have a complete web server running from your living room. Here is what you built:

Visitor yourname.duckdns.org Router Linux + Apache Your Page 🔒

📋 Quick Reference Cheat Sheet

Essential Commands

ip addr show — Find local IP

curl ifconfig.me — Find public IP

sudo systemctl status apache2 — Check Apache

sudo systemctl restart apache2 — Restart Apache

sudo ufw status — Check firewall

sudo certbot renew --dry-run — Test SSL renewal

Essential Paths

/var/www/html/ — Website files

/etc/apache2/ — Apache config

/etc/apache2/sites-available/ — Virtual hosts

~/duckdns/duck.sh — DNS updater

Ports

80 — HTTP (unencrypted)

443 — HTTPS (encrypted)

22 — SSH (local only)

Your server is yours. You control the hardware, the software, and the content.