Raspberry Pi Intranet Server

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!

Background Scenario

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.

  1. 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.
  2. 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.
  3. Change the default password.
  4. Set your locale and timezone.
  5. 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:

sudo raspi-config

The default Raspbian distribution is rather bloated for headless systems. At this point you should elect to remove some of the unnecessary cruft and extend the life of your SD card.

Install Lighttpd

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

Install PHP

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

Update Permissions

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:

http://raspberrypi/
http://192.168.1.101/

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:

fixed-address 192.168.1.101;

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):

ifconfig

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.

Next Steps

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.

6 Responses to “Raspberry Pi Intranet Server”

  1. Dave

    Brilliant blog, just what I needed. I’ve been trying to get a simple webcam working over our home network using Motion, Gstreamer, etc. to no avail. Within 20 minutes of following your instructions I’m up and running.

    Cheers!!

    Reply
  2. Dave

    Would like to host multiple sites for the intranet.
    – Wiki (DokuWiki – maybe more than one instance)
    – Blog – personal and family, and so forth.

    Each wiki and blog with their own domain name.

    Also would like to do it over a different port like 8080

    Is there a way? And can you help with the steps?

    Thank You For Your Time

    Reply
  3. Richard

    Personally, I’d just use Apache in that case, but if you’re committed to using lighttpd, try a mod such as mod_simple_vhost. Depending on your need to support various ports (you’ll need to refer to lighttpd documentation), your host configuration might look something like:

    $HTTP[“host”] =~ “(^|\.)example\.com(:\d+)?\\?$” { … }

    Reply
    • Dave

      Figured out how to have multiple websites in an intranet with Lighttpd and calling them by port number. Note that some file locations may be different on your setup as it depends on how lighttpd was setup.

      https://wiki.archlinux.org/index.php/Lighttpd is where I got the idea how to do this.

      Do not need to use Lighttpd’s vhost mod so in the Lighttpd config file it was commented out as;

      server.modules = (
      .
      # “mod_simple_vhost”,
      .
      )

      The server port was changed from the default of 80 to 8080.

      #### bind to port (default: 80)
      server.port = 8080

      Server Document root setting which is the main one tied to port 8080.

      server.document-root = “/var/www”

      Now to set up the additional sites by port number. At the bottom of the lighttpd.conf file add the following lines;

      $SERVER[“socket”] == “:8081” {
      server.document-root = “/var/www/sites/8081”
      index-file.names = ( “index.html, “index.htm”, “index.php”, “index.lighttpd.html” )
      # server.errorlog = “/var/log/lighttpd/error.log”
      # accesslog.filename = “/var/log/lighttpd/void.com/access.log”
      # server.error-handler-404 = “/e404.php”
      }

      $SERVER[“socket”] == “:8082” {
      server.document-root = “/var/www/sites/8082”
      index-file.names = ( “index.html”, “index.htm”, “index.php”, “index.lighttpd.html” )
      # server.errorlog = “/var/log/lighttpd/error.log”
      # accesslog.filename = “/var/log/lighttpd/void.com/access.log”
      # server.error-handler-404 = “/e404.php”
      }

      $SERVER[“socket”] == “:8083” {
      server.document-root = “/var/www/sites/8083”
      index-file.names = ( “index.html”, “index.htm”, “index.php”, “index.lighttpd.html” )
      # server.errorlog = “/var/log/lighttpd/error.log”
      # accesslog.filename = “/var/log/lighttpd/void.com/access.log”
      # server.error-handler-404 = “/e404.php”
      }

      The 8081 in …server.document-root = “/var/www/sites/8081″… could be any valid directory name such as dads-blog, moms-blog, network-notes, htpc-use, family-pictures and so forth. Just remember to create them in the proper place with the proper permissions.

      So users can easily upload files recommend setting up Samba, which is beyond the scope of this article but can easily be found by searching.

      You may have as many sites as you want just be sure to increase the …$SERVER[“socket”] == “:8083” {… better known as port number.

      To access the sites from your browser, in the address bar type the IP of your RPI/Lighttpd server followed by the port number as;

      192.168.1.12:8080 or 192.168.1.12:8082

      SECURITY: Strictly for internal intranet use. If you use this to allow outside internet access, you do so at your own peril and risk. Securing internet web servers is beyond the scope of this article. Since this is used in my home it works well for my families needs. Also since this is my family they know not to put anything on their area they would not want anyone else to see and share.

      Reply


Leave a Reply to Dave

  • (will not be published)