🛠 Serveur web ultra-léger ou conteneurs sur 256 Mo
Objectives
- Deploy a static web service that fits within 256 MB of shared CPU/GPU RAM.
- Compare approaches: busybox httpd (a few MB), Python http.server, and the limitations of containers on 32-bit ARMv6.
- Make the service persistent and expose it on the network via the WiFi dongle.
Hardware
- Model A in headless mode (WiFi/SSH tutorial completed), WiFi dongle or g_ether gadget.
busybox(already present on Raspberry Pi OS) or Python 3; for containers: unofficial podman/docker on ARMv6.- Web service directory: /srv/www, outside of /home.
Complete code
# Option 1 — busybox httpd : ~0 dépendance, empreinte minimale
mkdir -p /srv/www && echo '<h1>Model A en ligne</h1>' > /srv/www/index.html
nohup busybox httpd -p 8090 -h /srv/www -f &
# Option 2 — service systemd pour le redémarrage automatique
cat > /etc/systemd/system/tinyweb.service <<'EOF'
[Unit]
Description=Serveur web busybox
After=network-online.target
[Service]
ExecStart=/usr/bin/busybox httpd -p 8090 -h /srv/www -f
Restart=always
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable --now tinyweb
# Test local
curl -s http://localhost:8090/
Expected verification
curl returns the HTML; from a laptop: http://raspberrypi.local:8090/. free -m shows that the server uses a few MB and that there is still headroom. >
Common errors
- Installing full nginx + PHP + database: the whole stack saturates RAM and causes the SD card to swap.
- Serving on port 80 without checking availability: conflict with another service,
Address already in use. - Forgetting
-f(foreground) in the systemd service: httpd detaches and systemd restarts it in a loop. - Placing the site under /home/pi and then losing the password: prefer /srv/www and back up the card.
Other tutorials for this board
Code examples for this board
led_blink.pyPythonbutton_led.pyPythonservo_sweep.pyPythondht_temp.pyPythonoled_i2c.pyPythonmcp3008_read.pyPython