Thursday, May 16, 2013

Personal Raspberry Pi Web Server

Hasta la vista, hosting fees!  If you have a crappy website that maybe gets a couple visits per day, and you are paying more than $0.50/month for hosting, this project is for you.  The Raspberry Pi is a small computer that can run a linux web server.

Based on some power consumption measurements seen online, this device should cost less than $3 per year in electricity, assuming $0.06 per kWH

My site, is currently running in this manner, although it is a pretty light-weight on the php end, only using php include commands.  Joomla and wordpress page load times would be longer, although there are ways around this using built-in caching.

Step 1, buy a Raspberry Pi (unless your brother got you one for your birthday - thanks Eric!)

Step 2, download the latest raspbian release, and burn it to an SD flash card - you will need a card reader and software that can write an image to a flash card.  Most laptops have built-in card readers now days.  Some good instructions here on creating the SD card image.

Boot up your pi.  you can use a keyboard/mouse to do initial configuration, or you can wait for it to get a dhcp address from your router or firewall, and connect via telnet (I prefer to use PuTTY for this).
The default login details:

user: pi
password: raspberry
sudo passwd pi   
It will then prompt for a new password.

Give it a static IP.  note this IP for when you configure port forwarding on your firewall.

Next, you can run the usual debian commands to get apache or whichever web server you want to use..
sudo apt-get install apache2 php5 libapache2-mod-php5
sudo apt-get install mysql-server mysql-client php5-mysql

sudo apt-get install vsftpd

Next, take ownership of the web root:

sudo chown -R pi /var/www

Connect your ftp client to the PI, and transfer the files.  The default directory is /var/www

Now for the DNS tricks to get this to work:
Log in to your firewall - forward ports 80 and 443 to the Pi IP address.  This makes it public, but you need DNS to let people find the Pi.
Go to and set up an account.  Set up a free subdomain ( like - it will default  to use your IP address.  If your ip address changes, you will need to go back to the site to update it there, although it is a pretty easy process.  There may be a way to automate this using a cron job... or you can also install the client for windows to update the address automatically (when the computer is running)

Next, log in to your registrar (godaddy, netsol...) and forward the domain with masking to your new dynamic dns address.  The masking feature keeps the original address in the address bar, so users are not confused by your dnsdynamic address.

The change may take some time as dns changes sometimes do.  make a small change to your old hosted location so that you can tell when it is loading from the pi.  Or better yet, add a raspberry icon to the new site!

Dial up your site, and if it works, cancel the old hosting plan.  Then just wait 1 year to recoup investment in time and money.

Special thanks to others who have done this already;

No comments:

Post a Comment