---
title: "Lab: Your Own Web Server in One Command"
domain: cloud-computing
level: foundations
duration: "30 min"
cost: "free"
environment: "your own computer (Windows, macOS or Linux) with Python 3 and a web browser; no account, no Internet needed"
---

# Lab: Your Own Web Server in One Command

## Goal
Turn your own computer into a tiny web server, open its page in a browser, and watch the server write down every request it receives. You will see the request and response from the lesson with your own eyes.

## Objectives
- Run a small web server on your own computer and open it in a browser.
- Read a server's log line and say what each part means.
- Explain what a `404` is and see one happen.

## Prerequisites
- [The lesson of this module](lesson.md).
- You know how to open a terminal and move between folders ([module 02](../02-terminal-basics/README.md)).
- **Python 3**. Check by typing `python3 --version` (macOS and Linux) or `python --version` (Windows) in a terminal. It should print something like `Python 3.12.3`; any 3.x version works.
- A web browser and a plain text editor (Notepad, TextEdit in plain-text mode, gedit, VS Code…).

> [!WARNING]
> The server you start is reachable only from **your own computer**, because of `--bind 127.0.0.1`. Don't remove that option, and stop the server (Step 5) when you finish. Windows may ask whether to allow Python through the firewall; with this option you can safely choose to **cancel** or **deny**.

## Architecture
![Everything happens on your computer. A browser with the address http://127.0.0.1:8000 sends a request, arrow 1, to a Python web server started with python3 -m http.server 8000 --bind 127.0.0.1. The server reads index.html from the folder ~/my-website and sends it back as the response, arrow 2. In the terminal, one log line appears for each request, for example GET slash with status 200 and GET slash x with status 404. A note says 127.0.0.1 means this computer, so nobody else can reach the server.](../../../assets/diagrams/webserver-lab-architecture.svg)

*Figure 1. The browser is the client, the Python program is the server, and the terminal shows a line for every request.*

## Steps

### Step 1 — Make a folder with one web page (8 min)
A web server needs files to serve. You create a folder called `my-website` and put one page in it.

In your terminal, create the folder and go inside it:

```bash
mkdir ~/my-website
cd ~/my-website
```

On Windows PowerShell the same two lines work as written.

`mkdir` makes a folder, `~` is your home folder, and `cd` moves into it. Now open your text editor and create a file named **`index.html`** inside this folder, with exactly this content:

```html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>My first website</title>
  </head>
  <body>
    <h1>Hello from my own server!</h1>
    <p>This page is a file on my computer.</p>
  </body>
</html>
```

This is HTML. `<h1>` marks a big heading and `<p>` a paragraph. The text in `<title>` appears in the browser tab. Save the file, making sure the name is `index.html` and not `index.html.txt` (Windows hides extensions by default; Notepad's "Save as type" must be "All files").

Check that the file is there:

```bash
ls
```

On Windows PowerShell, `ls` works too.

Expected output:
```text
index.html
```

Why `index.html`? When someone asks a web server for `/`, the server looks for a file with this name. It is the default home page.

### Step 2 — Start the server (5 min)
Still in `~/my-website`, run:

```bash
python3 -m http.server 8000 --bind 127.0.0.1
```

On Windows, use `python` instead of `python3` (or `py` if `python` is not found).

Expected output:
```text
Serving HTTP on 127.0.0.1 port 8000 (http://127.0.0.1:8000/) ...
```

Line by line, the command means:

- `python3 -m http.server` runs a small web server that comes with Python. It serves the files of the folder you are in.
- `8000` is the **port**, the door number (the lesson explained ports).
- `--bind 127.0.0.1` makes it listen only on `127.0.0.1`, the address that always means "this computer".

The terminal now seems to be "stuck": no new prompt appears. That is normal. The server is running and waiting for requests, and this terminal window is where it reports. Leave it open.

> [!NOTE]
> If you see `OSError: [Errno 98] Address already in use` (on Windows, a message about the address being in use), another program already uses port 8000. Choose another port, for example `8001`, and use it everywhere this lab says 8000.

### Step 3 — Visit the page and read the log (8 min)
Open your web browser and type this address in the address bar:

```text
http://127.0.0.1:8000
```

You should see a page with the big heading "Hello from my own server!" and the tab titled "My first website". You just used your computer as both the client (the browser) and the server (Python).

Now look at the terminal. New lines appeared. The date and time on your screen will differ, and your browser may also show a second line for `/favicon.ico`, the little tab icon it always asks for:

```text
127.0.0.1 - - [07/Nov/2026 21:48:34] "GET / HTTP/1.1" 200 -
```

Read it from left to right:

| Part | Meaning |
|---|---|
| `127.0.0.1` | Who asked: the address of the client. Here it is your own computer. |
| `- -` | Two fields that servers can fill with login details. Here they are unused. |
| `[07/Nov/2026 21:48:34]` | When the request arrived. Yours will show the current date and time. |
| `"GET / HTTP/1.1"` | The request: the method `GET` ("send me this"), the path `/` (the home page), and the version of HTTP. |
| `200` | The status code: OK, the server found the file and sent it. |
| `-` | The size of the answer, left empty by this simple server. |

Think about it before opening the answer: you never typed `index.html` in the address, so why did the server send it?

<details>
<summary>Show the answer</summary>

The path in the request was only `/`. A web server answers `/` with the folder's default page, which is called `index.html`. You could also type `http://127.0.0.1:8000/index.html` and get the same page. Reload that address and look at the log: a new line `GET /index.html` appears.

</details>

### Step 4 — Change the page, then ask for a page that doesn't exist (6 min)
The server doesn't keep the page in memory: it reads the file every time. So you can change the page without restarting anything.

Open `index.html` in your editor, change the text inside `<p>…</p>` to something new, for example `I just edited this page!`, and save. Go back to the browser and **reload** it (F5, or Cmd+R on a Mac). The new text appears. A new `GET / ... 200` line appeared in the terminal.

Now ask for a file that doesn't exist. In the address bar type:

```text
http://127.0.0.1:8000/about.html
```

The browser shows an error page, "Error response: Error code: 404, Message: File not found". Look at the terminal:

```text
127.0.0.1 - - [07/Nov/2026 21:48:34] code 404, message File not found
127.0.0.1 - - [07/Nov/2026 21:48:34] "GET /about.html HTTP/1.1" 404 -
```

What changed compared with the first log line, and does a 404 mean the server is broken?

<details>
<summary>Show the answer</summary>

The path is now `/about.html` and the status code is `404` instead of `200`. A 404 does **not** mean the server is broken: the server is working fine and answered, saying "I have no file at that path". In this case the file doesn't exist in `~/my-website`. As a challenge you can create `about.html` and reload; the 404 turns into a 200.

</details>

### Step 5 — Stop the server (3 min)
Go to the terminal where the server is running and press **Ctrl+C** (hold the Ctrl key and press C).

Expected output:
```text

Keyboard interrupt received, exiting.
```

The prompt comes back. Now go to the browser and reload the page: it shows an error such as "Unable to connect" or "This site can't be reached". Nobody is listening at port 8000 any more, so the request gets no answer at all. That is different from a 404, where the server answers.

## Verification
You have completed the lab if:

- The browser showed your "Hello from my own server!" page at `http://127.0.0.1:8000` while the server ran.
- The terminal showed a log line ending in `200` for it and a line ending in `404` for the missing page.
- After Ctrl+C, the browser could no longer connect.

## Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| `python3: command not found` | Python is not installed, or on Windows it is called `python` | Install Python 3 from python.org, and on Windows type `python` or `py` instead of `python3` |
| `Address already in use` | Another program uses port 8000, or the server is already running in another terminal | Stop the other one, or use another port such as `8001` in the command and the address |
| The browser shows "Directory listing for /" or a 404 for `/` | You started the server in the wrong folder, or the file is not named `index.html` | Press Ctrl+C, run `cd ~/my-website`, check with `ls` that `index.html` is listed, and start again |
| Edits don't appear | The page is cached or the file was not saved | Save the file, then force-reload (Ctrl+F5, or Cmd+Shift+R on a Mac) |
| `index.html.txt` in the listing | The editor added `.txt` | Save again as "All files" with the name `index.html` |

## Challenge (optional)
1. Add a second page, `about.html`, with your name in a heading, and link to it from `index.html` with `<a href="about.html">About</a>`. Click the link and find the matching line in the log.
2. Stop the server and start it on port 9000. Which address must you now type in the browser?

## Cleanup
The lab created one folder and nothing else. Make sure the server is stopped (Ctrl+C), then remove the folder.

On macOS or Linux:

```bash
cd ~
rm -r ~/my-website
```

On Windows PowerShell:

```text
cd ~
Remove-Item -Recurse ~/my-website
```

## What you learned
- Any computer becomes a server when it runs a program that answers requests; yours did it with one command.
- A request has a method and a path, and a server's answer starts with a status code: `200` for success, `404` for "nothing here".
- The server reads files from a folder, and `index.html` is the default page of a folder.
- Binding to `127.0.0.1` keeps a test server private to your own computer, and Ctrl+C stops it.
