Fundamentals 12 min read

How to Set Up Raspberry Pi Zero W: OS Install, SSH, and Web Server

This guide walks you through understanding what a Raspberry Pi Zero W is, preparing the SD card, flashing Raspbian Stretch Lite, configuring SSH and Wi‑Fi, optimizing the system, installing Nginx, and exposing the device to the internet with ngrok, all with step‑by‑step instructions and code snippets.

Programmer DD
Programmer DD
Programmer DD
How to Set Up Raspberry Pi Zero W: OS Install, SSH, and Web Server

Introduction

The author discovered the Raspberry Pi and decided to document the entire process of setting up a Raspberry Pi Zero W.

What is a Raspberry Pi?

Raspberry Pi (RPi) is a credit‑card‑sized Linux‑based micro‑computer designed for learning programming. The Zero W model is a miniature version, about one‑third the size of a 3B+, with a 1 GHz single‑core CPU, 512 MB RAM, Wi‑Fi/Bluetooth, HDMI, USB OTG, GPIO, and micro‑SD storage.

Zero W specifications

BCM2835 processor, 1 GHz, 512 MB RAM

BCM43438 Wi‑Fi/BT chip

Micro‑USB power and OTG ports

Mini‑HDMI port

Composite video and reset pins

CSI camera connector

Micro‑SD slot for OS

40‑pin GPIO header

Dimensions: 65 mm × 30 mm

Despite its modest hardware, it can comfortably run a small website.

Installing the OS on Zero W

Preparation

16 GB or 32 GB SanDisk micro‑SD card

Standard USB‑type‑A cable (not USB‑C)

SD card formatting tool (e.g., SDFormatter)

Win32DiskImager

Raspberry Pi OS image (Raspbian Stretch Lite)

Raspbian Stretch Lite is the official minimal image without a desktop environment, saving space and resources.

Step 1 – Download the image

Download the desired image (a ~360 MB zip file), unzip it to obtain the .img file (~1.7 GB).

Step 2 – Write the image to the SD card

Insert the SD card into a reader, open Win32DiskImager, select the .img file, choose the correct device, and click “Write”.

Step 3 – Modify the boot partition

After writing, the card shows a boot partition (~40 MB). Create two empty files in this partition:

ssh – an empty file (no extension) to enable SSH on first boot.

wpa_supplicant.conf – with the following content (replace with your Wi‑Fi SSID and password):

country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="your_wifi_name"
    psk="your_wifi_password"
}

Step 4 – Assemble and power up

Insert the prepared SD card into the Zero W, connect power via a USB‑A cable, and wait for the LED to stabilize. Locate the device’s IP address on your router (e.g., 192.168.0.104).

Use an SSH client (e.g., PuTTY) to connect with username pi and password raspberry.

Optimizing the system

1. Change package sources

Replace the default mirrors with a faster domestic source (e.g., USTC):

sudo nano /etc/apt/sources.list
# comment existing lines and add:
deb http://mirrors.ustc.edu.cn/raspbian/raspbian/raspbian stretch main contrib non-free rpi
sudo nano /etc/apt/sources.list.d/raspi.list
# comment existing lines and add:
deb http://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian stretch main ui
sudo apt-get update
sudo apt-get upgrade

2. Set timezone

sudo dpkg-reconfigure tzdata

Select Asia → Shanghai.

3. Enable SSH on boot

Method 1: sudo raspi-config Navigate to “Interfacing Options → SSH” and enable it.

Method 2 (manual): add /etc/init.d/ssh start before the exit 0 line in /etc/rc.local.

Installing Nginx

# Install
sudo apt-get install nginx
# Start
sudo /etc/init.d/nginx start
# Restart
sudo /etc/init.d/nginx restart
# Stop
sudo /etc/init.d/nginx stop

Access http://192.168.0.104 to verify the web server.

Exposing the device to the internet

Use a tunneling service such as ngrok, frp, or similar. The author chose the free ittun ngrok client for ARM.

Run ngrok in a screen session to keep it alive in the background.

Additional notes

The Zero W can run additional services, and its resource usage remains low (≈250 MB free RAM, CPU temperature 37‑39 °C after two days of operation).

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Raspberry PiSSHngrokZero W
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.