Web Hosting at Home on a Raspberry Pi

It has been a learning experience moving my 8 domains (including this one) from a ~$10/month hosting service* to a home server built on the Raspberry Pi. Not counting the small amount of time in labour (possibly 8 hours of learning/testing/configuring things, as I am a novice Apache tinkerer**), I will see savings before 2014 is up. The annual cost of virtual hosting with a hosting company, with a decent Linux server, software installation, full on access to mod-rewrite, unlimited MySQL, etc is ~$135. The Raspberry Pi ($47 CDN) can’t do it out-of-the-box (you need to buy a power supply and 2-4 GB SD card to get the Pi going, plus an 8+ GB USB stick to run it as an effective web server), but the costs were just shy of $100 (all figures in Canadian dollars, taxes in). Pi_boxed_up_2014-01-10 Pi_Parts_2014-01-10 Isa_assembling_Pi_2014-01-10 Feelin' N00BY Pi_online_2014-01-10 Isa_configs_Raspbian_2014-01-10 PI_MOUNTED_USB_FINALLY_2014-01-11The next step was to do research on software dependencies and configuration, exploring the accounts of others who had successfully used the Pi as a home web server (I’ve included most of the resources I consulted at the bottom of this post). But what started out as simple research led to a confusing mess for a while. Why? Well there are many assumptions among those who are working in particular system configurations (diff flavours of Linux, or in Mac OS) that get overlooked when these authors try to explain and document their processes. I’ll probably be guilty of the same. Perhaps more importantly than this, though, is that in the process of trial and error with following different sets of instructions, it dawned on me that I lacked some fundamental knowledge about (1) how disks behave when they are mounted vs unmounted and (2) how IP addresses and name servers operate, details I only required an abstract understanding of when working with websites hosted with a paid service. Once in the trenches of Apache on Raspbian, I found myself grasping at straws at times. Eventually I found my way, though. Here are the most essential links I collected as I went along, organized by class of challenge:

1. RASPBERRY PI CONFIGURATION You need to use a USB disk drive to store your websites where the public will access them. SD cards don’t have a very long life when they get constantly written and read over and over again, so the consensus goes. You also have to look at your sites to figure out how much space you’ll need (I only really need about 1GB for mine, all wordpress save one, and minimal media serving), as well as anticipate near future changes (do I want to run a home media server? torrents?, etc.). Then you should be able to figure out what size of USB stick to get. Prices and quality vary much more than you might think. I settled on a 16 GB Lexar S23 USB flash drive, which cost me 10 bucks. It’s compact and gets very good reviews for speed and reliability, and there is no point in stepping up to a high grade USB 3.0 drive (the Lexar P10 for instance), because the Pi USB ports are only USB 2.0. Time will tell if I made the correct choices here, but for now, everything’s working all snappy-like. You need to get Raspbian from the RPi community and install it to the SD card, using a computer (mine is a PC with Ubuntustudio 13, so I used a tool called GParted to manage the formatting of drives and partitioning. It really helps here if your computer/laptop has an SD card slot, as mine does. I used N00Bs to install Raspbian to the SD card, and then moved the SD card to the Pi SD card slot, where we did configuration using an Apple keyboard and mouse plus our Samsung TV (the only thing in the house that takes HDMI input – the Pi has no VGA out, of course). Working from my laptop on the same network via SSH (and occasionally swapping the SD card back and forth between the Ubuntu machine and the Pi to correct stupid mistakes) I was able to do some basic configurations on the Pi, such as the ALL TOO IMPORTANT step of instructing it to ALWAYS mount the USB flash drive on startup, among other important steps. Then, you need to configure the RPi so that it uses the SD card as a BOOT volume, but then automatically boots into the OS installed on the USB stick. This involves copying Raspbian to the USB drive, and then editing a couple of files in the SD card’s BOOT directory, along with partition-filling and error checking – lots of command lines. It all makes perfect sense in retrospect, but I admit it’s easy to get lost and discouraged at this stage. Links for the above steps: http://raspberrywebserver.com/serveradmin/connect-your-raspberry-pi-to-a-USB-hard-disk.html http://magnatecha.com/using-a-usb-drive-as-os-root-on-a-raspberry-pi/ http://c-mobberley.com/wordpress/index.php/2013/04/13/moving-raspberry-pi-root-folders-from-sd-card-to-usb-hdd/

2. APACHE WEB SERVER CONFIGURATION This was nowhere near as complex and challenging as configuring the Pi to use disks like it should, but this one had its difficulties, as well. As a general guide toward getting all of WordPress’ dependencies set up I followed Dingleberry Pi’s great set of instructions (though these are Mac OS-oriented). Other useful links are below, relevant to configuring virtual hosting in your Apache server, and understanding that different Linux distros have the Apache config file in different places. http://httpd.apache.org/docs/2.2/vhosts/examples.html http://wiki.apache.org/httpd/DistrosDefaultLayout

3. FINALLY, DNS CONFIGURATION I actually set this up ahead of time. You have to grab an account at dlinkdns.com first, and then use that account to set up free DNS hosting at dyn.com. More specific instructions here. Relevant links below: http://dyn.com http://dlinkdns.com/ The last steps involved configuring one virtual host, installing WordPress in its directory, enabling port forwarding on my router to the Pi machine, and then resetting my DNS pointers on one domain as a test site. Then I waited a day to see if the domain resolved to a fresh WP install rather than the old blog. Once that happened I was on to straight-ahead WordPress imports, which can all be done within WordPress, then rinse and repeat for the six other blogs. I plan to tinker some more with a mail server, server monitoring tools and much else using the Pi in the next few months. In the meantime, drop me a line if this website seems slow, acts strange, or goes offline.

Notes: *I was with canadianwebhosting.com, and they are an outstanding service, especially considering the competitive rates – highly recommended!) **I am a n00b with Apache, and moderately challenged in unix commands. I shouldn’t say that. I’ve come back to and gone away from code over the past decade and a half, but never committing myself to more than the odd Yahoo Pipes trickery, Twitter API hack, or intentional hijacking of a Worpress plugin. Which isn’t really much, but it’s sufficient to really get out of n00bspace. I digress…