Wednesday, November 28, 2012

How to host your own website on a Raspberry Pi


How to host your own website on a Raspberry Pi

Requirements

Hardware:
Raspberry Pi
USB power cable
Ethernet cable and modem to connect to
HDMI cable (temporary need)
Monitor (temporary need)
USB mouse/keyboard (temporary need)
Standard SD card
SD card reader on your computer

Software:
Raspbian image - Debian based OS for Raspberry Pi
Lighttpd - lightweight webserver that is extremely easy to set up
PageKite - makes local websites or SSH servers publicly accessible in mere seconds, and works with any computer and any Internet connection.

Also you will need to buy a domain for your site.  I purchased mine through hover.com, but there are many to chose from.



First you need to setup the SD card on your Raspberry Pi.

The SD card is the harddrive for the Raspberry Pi, you'll be installing Raspbian which is a derivative of Debian.  If you are familar with Linux you'll be right at home.

Here is the guick start guide for Raspbian:
http://www.raspberrypi.org/quick-start-guide

Install the latest "Raspbian" SD card image from here:
http://www.raspberrypi.org/downloads

Just follow the instructions to download the image and install it on your SD card, once we actually boot the Raspberry Pi you will set it up.

Now, here is where you temporarily need to  have a monitor, keyboard, and mouse that you can use to run your Raspberry Pi.

If you don't have a monitor, mouse and keyboard, you can set up your Raspberry Pi in headless mode.  Here is a link to to this, although I did not utilize this method:
http://www.penguintutor.com/linux/raspberrypi-headless

Now plug in the ethernet from the Raspberry Pi to the modem, HDMI from the Raspberry Pi to the monitor, USB to your keyboard and mouse.  Plug in the SD card that you
installed Raspbian and last plug in the power.  Plugging in power is how you power on the Raspberry Pi.  Go through the on screen setup, be sure and change the password,
turn on SSH, set the date/time and any of ther other setup options that you think you'll need.  Complete the setup and pat yourself on the back, you are on  your way.

Next step, setup a static IP on your router so the Raspberry Pi always has a static IP in your home network.  Here is tutorial that I followed for this
step:  http://www.penguintutor.com/blog/viewblog.php?blog=6306

Once you complete this come back here to continue the setup.

Good job so far.  Let's use some of our Linux skills now(I'm a huge Linix fan, it's all I run on my PCs), don't worry, it won't hurt.

Open the terminal and run the following command:
sudo apt-get install lighttpd

Did you press enter at the end of that last row?  You should.
Now run the command:
sudo reboot

While your rebooting here is something to read:
lighttpd is a lightweight open source webserver.  It is pronounced "Lighty" and it will listen for requests on port 80, when it receives a request
it sends back the requested webpage.

Ok and we're back.  So you should be rebooted now so let's check to see if lighttpd is doing it's job.  Type in the IP that you assigned to your
Raspberry Pi, for instance 192.168.1.10, on your browser.  You can do it on your computer or on the Raspberry Pi's browser, it's called Midori.
You should get a webpage showing that lighttpd is working.  The file that is being displayed is sitting on the Raspberry Pi at /var/www/ and it's
named index.html.  This folder is where you will place your website.  You have created your website already right?  If not, you can do that once you
have completed this setup.  I used a starter page from http://www.styleshout.com/.

Ok you're doing great, we're getting near the end.

Next we are going to set up an account with PageKite.  PageKite charges $36/year for an account.  There are free options like Dyndns, but I have
Verizon fios and am forced to use their router, thus my Dyndns did not work well for me.  If you wan to use Dyndns, you can set up a free account
that should work for you.

PageKite is easy to install, just visit their page from the Raspberry Pi and setup an account and install the software.  You will be installing
the Linux version and the site walks you through all the steps.  Make sure your account id is NOT the same as the site you are setting up.  You will
use the site name also as a secondary pagekite.  Once you have your account set up with PageKite, you will need to follow this guide to setup
PageKite to point to your own doman:  https://pagekite.net/wiki/Howto/CnamePageKites/

For step 2 above, if you went with hover.com, you'll need to add a new DNS with the following format:
Hostname:  www  
Record Type:  CNAME
Target Host: sitename.accountid.pagekite.me

Complete the CnamePageKites setup and then you are done!  Your website is now live on the web!  See that really wasn't very hard to do.