This article will help you set up a simple, fast, light-weight web server on your home network intranet. Please note that by definition the end result is not intended to be suitable for an HTPC, a publicly accessible web site, or a media server, etc.
Author’s Note: Disclaimer for the anticipated wrath of the inevitable Raspberry Pi Fanbois — Yes, an RPi can absolutely be used in those capabilities. I, myself, use one of my Pi’s as a surprisingly capable XBMC-based media center, but support for those heavy-duty applications is the exact opposite focus of this article!
As a web professional, business owner, and web host provider for any friend or family member who needs free hosting, I have several server deployments in various data centers of Amazon, GoDaddy, Google, DreamHost, A Small Orange, and probably a few others. So access to web-based hosting isn’t exactly an issue for me.
Sometimes I just need access to certain information only while I’m at home. Since the majority of our home network is hard-wired into a central patch panel — along with phone lines, and central video and audio — and we have a photovoltaic (solar) power-generation system, I have accumulated a lot of configuration and operating data that I refer to every now and then while carrying an iPod or netbook around my home. The information could also be useful for the next homeowner; serving it up from a permanent intranet web server that I can just leave hard-wired in the home when we move out would be ideal — and it could be a great sales bullet point for the Realtor listing!
A $35 low-power Raspberry Pi fits the requirements perfectly. Accessories may cost you more, but I initially built a tight-fitting case for free with Legos in order to retain the ability to easily access on-board pin-outs for other development projects. I eventually added an inexpensive Pi case for my “production” server.
Configure the Operating System
Plug in your network cable and micro USB power source. When first booting with the recommended Raspbian operating system, a raspi-config setup menu allows you to easily make some necessary configuration changes. The initial configuration will require a TV with composite video or HDMI input, as well as an appropriate RCA or HDMI cable, plus a basic USB keyboard.
You should minimally perform the following tasks with raspi-config before you begin the rest of the setup of the intranet server.
- Expand your root partition on your SD card to its fullest. Alternatively, you can create multiple volumes on the drive, but that’s beyond the scope of this article.
- Ensure the keyboard layout settings match your USB keyboard, if you need one. Note that by default, Raspbian installs the UK keyboard layout which is different than the US layout.
- Change the default password.
- Set your locale and timezone.
- Enable the SSH server
Log into your Raspberry Pi with user ‘pi’ and the password you set above, either by an attached keyboard and monitor, or via SSH (enabled above). On my Mac, I type the following to access my Pi:
ssh raspberrypi -l pi
If you have already gone through the setup once before and you wish to run it again, type the following once you’ve logged in:
Because of their power, reliability, and feature sets, the proven pairing of Apache and MySQL has become the defacto standard for web applications, so much so that WAMP and LAMP have become common acronyms for Apache and MySQL installations on Windows and Linux machines, respectively. I generally use Apache and/or Tomcat for my professional projects because I need that power and reliability.
That said, you don’t need a sledgehammer to crack open a nut. Because my simple project doesn’t need the power or complexity of Apache, I choose to install lighttpd, a small light-weight, single-threaded, single-process web server which performs well on the low-power Raspberry Pi. For the same reasons, if my Pi project needed a database, I would have used something small and light-weight like SQLite over MySQL.
sudo apt-get install lighttpd
If being light-weight was my primary concern for the Pi project, the inclusion of Perl within the default Raspbian installation may have been sufficient. However, for expediency, simplicity, convenience, and reuse of existing code, installing PHP opens up access to myriad readily available software packages and libraries.
sudo apt-get install php5-common php5-cgi php5
Enable FastCGI in order to allow lighttpd to handle PHP requests:
sudo lighty-enable-mod fastcgi-php
When the installation is complete, restart the lighttpd server:
sudo service lighttpd force-reload
If you want easier, non-root access to modify your web server files, change the permissions on the www directory and add the pi user to the www-data user group created by default in Raspbian:
sudo chown www-data:www-data /var/www sudo chmod 775 /var/www sudo usermod -a -G www-data pi
Test the Web Server
Assuming a vanilla Raspbian installation and depending on your network/router configuration, you might be able to access your new web server by simply typing “http://” followed by the hostname (usually ‘raspberrypi’) into your web browser address bar. Alternatively, type “http://” followed by the actual IP address of the network interface on your Raspberry Pi. Examples:
You should see a standard welcome placeholder page. It will be the same page no matter which URL you use to access it. Please note that your IP address is probably not 192.168.1.101.
Find the IP Address
You might not know the IP address of your RPi. Configuring your network is outside the scope of this document, so the assumption is that the Pi is connected via Ethernet cable to a DHCP-enabled router. To obtain the assigned IP address of the built-in network interface of the Raspberry Pi, type the following:
grep -h fixed-address /var/lib/dhcp/*
You should see something like the following:
Alternatively, if you manually configured your IP address, are using a USB WiFi adapter, or would just rather type less and read more, simply hunt through the output of the following command for your IP address, usually in section “eth0″ (the built-in network interface), “eth1″ (a USB NIC), or even “wlan0″ (a USB wireless network adapter):
Most of the time on a home network, the IP address of a computer or device usually starts with “192.168.”, and the last set of the four sets of numbers usually are not “0”, “1”, or “255”. Computers on networks using an Apple Time Capsule or Airport Extreme as a router often have IP addresses that start with “10.0.” or “172.16.”, the other two common private network ranges.
Delete the default lighttpd web page and replace it with your own:
sudo rm /var/www/index.lighttpd.html
Personalize your private, intranet web server with any number of available software packages. For my project, I installed DokuWiki, a mid-level, file-based, collaborative web text editor; somewhere between little-too-simple PmWiki and the complex, database-driven MediaWiki.
Other ideas include:
The rest is up to you.