This very webserver

Background

As a technical challenge (and to avoid 3rd-party hosting fees!) I wanted to use one of my Raspberry Pi‘s as a web server in a common LAMP setup.

Hardware

The Pi itself is a “Model B” so fundamentally I’m playing with a single core 700 Mhz CPU and (very nearly) 512 MB of RAM.

The hardware requires an SD card to boot an OS, in this case Raspbian. I’ve chosen a reasonably priced and pretty nippy Class 10, 8GB, SDHC card.

As web servers can generate relatively high amounts of filesystem I/O I’ve repurposed an old 64 GB USB SSD to help offload some of this traffic.

The Pi is physically hosted at my home and hooked up to the ‘net via a Plus.net Fibre Optic line.

Software

The base system is:

  • Linux in the guise of the Debian-based Raspbian distro,
  • Apache as the web server software,
  • MySQL for the RDBMS,
  • PHP for the scripting language.

WordPress will be used for the website’s CMS.


Tweakages

Out-of-the-box this LAMP mix is not great on the relatively meagre resources of a Raspberry Pi so a fair bit of tweaking will be needed to keep the system stable and optimal.

Hardware & OS

The first obvious area for optimisation is the SD card which drives the whole show:

  1. The number of read/write cycles to any form of flash memory device is finite. SD cards are best suited to infrequently storing large files e.g. Images from Digital Cameras. Even with an SD card’s built-in wear leveling it’s better to use storage media that’s more suited to the task.
  2. SSDs are about 10 times faster than SD cards:
    Media Read (MB/s) Write (MB/s)
    Transcend Class 10 SD card 20 17
    Kingston SSD 200 110
  3. SSDs tend to be a little more capacious than SD cards; 64GB vs 8GB in this case.

Things we can offload to the SSD without violating the Filesystem Hierarchy Standard too much:

  • /srv directory. This will include web site files.
  • /var/lib/mysql; MySQL data directory
  • /var/swap; The OS’s swap file

DRAFT

Using the lightweight Alternative PHP Cache to deliver pages and a few free CDNs for popular  code libraries and Amazon S3 for my own content and a bunch of OS tweaks.