🛠 Héberger un serveur web léger sur 256 MB de RAM
Objectives
Transform the Model B Rev 1 into a small permanent web server, taking into account its two bottlenecks: 256 MB of RAM shared between CPU/GPU and 10/100 Ethernet behind the LAN9512 chip. Apache is excluded; we choose lighttpd (or busybox httpd) with a few static pages and a status endpoint. You will learn how to size gpu_mem, serve via systemd, and measure the actual throughput.
Hardware
- Raspberry Pi Model B Rev 1 running a legacy 32-bit image (lite, without desktop)
- Wired Ethernet network (no WiFi on this board)
sudo apt install -y lighttpd curl- SD card with limited write endurance: avoid verbose logs, as the SD card wears out.
Complete code
# 1) Liberer de la RAM pour le CPU : /boot/config.txt -> gpu_mem=16
# (pas d'usage GPU prevu), puis sudo reboot
# 2) Installer et demarrer lighttpd
sudo apt install -y lighttpd
sudo systemctl enable --now lighttpd
# 3) Page de statut dynamique (CGI shell minimal)
sudo mkdir -p /srv/www && echo 'server.document-root = "/srv/www"' | sudo tee /etc/lighttpd/conf-enabled/99-site.conf
printf '#!/bin/sh\necho "Content-Type: text/plain"\necho\nvcgencmd measure_temp\nvcgencmd measure_clock arm\nfree -m | head -2\n' | sudo tee /srv/www/status.cgi
sudo chmod +x /srv/www/status.cgi
echo 'cgi.assign = ( ".cgi" => "" )' | sudo tee -a /etc/lighttpd/conf-enabled/99-site.conf
sudo systemctl restart lighttpd
# 4) Tester depuis un autre poste
curl http://192.168.1.50/status.cgi
# 5) Debit reel (test depuis le PC, attendez-vous a ~5-9 MB/s max)
scp page-test-10Mo.bin pi@192.168.1.50:/tmp/
Expected verification
curl http://<ip-du-pi>/status.cgi returns the temperature, ARM clock, and free memory. free -m shows 150-200 MB available with lighttpd alone. The server remains stable in permanent service; transfer throughput caps at a few MB/s, consistent with 100 Mbps Ethernet shared with USB.
Common errors
- Installing Apache or Nginx with PHP: on 256 MB (with default gpu_mem of 64-128 MB), the OOM killer terminates workers; reduce gpu_mem and stick to lighttpd.
- Forgetting
gpu_mem=16: without video usage, you waste a quarter of the RAM. - CGI shell on every request: vcgencmd is slow on ARM11, cache the results (file regenerated by cron) if traffic increases.
- Lighttpd logs looping on the SD card: enable rotation or log to memory.
- Exposing the server to the Internet without a proxy or firewall: the board has no hardware encryption, and lightweight HTTPS (lighttpd + SSL) consumes a lot of CPU per request.
Other tutorials for this board
- Allumer une LED via le GPIO avec libgpiod
- Lire un bouton poussoir et afficher l'état dans la console
- Premier script Python : faire clignoter la LED
- Variation d'intensité LED avec le PWM matériel (et son piège)
- Lire un capteur I2C (température/humidité) sur le bus 1
- Configurer l'Ethernet 10/100 et piloter le Pi en SSH
Code examples for this board
led_blink.pyPythonbutton_led.pyPythonservo_sweep.pyPythondht_temp.pyPythonoled_i2c.pyPythonmcp3008_read.pyPython