Stuff what I did

Raspberry Pi Web Server —

This site is hosted on a credit card sized computer costing about £35 and a few pence per day in electricity. Yes, it’s a wimp in comparison to most computers and there are far easier ways to create a website, but where is the fun, challenge and learning in that?

If you need a full tutorial on how to do this then try this one.
As usual I didn’t follow the recipe precisely so what follows are just my notes, in case I need to retrace my steps.

The Hardware: A model B rev.2 Raspberry Pi. The version with 512MB of memory.

I’m using an 8GB SD card (a basic website could squeeze onto 2GB but this is what I had spare), it’s wired to my network router (although wireless would be fine), has a 5v power supply and I only needed a keyboard and screen for the initial operating system setup.

The Operating System: Raspbian-Server-Edition (aka RSE)

Hats off to SirLagz for his work to create a cut-down version of Raspbian.
When creating any server it is best to start with the absolute basics and to then add just what you need. You are then not wasting storage, memory and processing power on services that you don’t need.
Your server should also be more secure because you’ll know each service that you have loaded and by building a server in this way you’ll also learn more about the OS.
(Arch Linux is a good alternative but I’m more familiar with the Debian based distros and if this website is going public I want to be sure I’ve got it right.)

RSE doesn’t contain many packages but to make sure they’re all up to date use:

sudo apt-get update
sudo apt-get upgrade

OS Configuration: Raspbian comes with an easy config editor:

sudo raspi-config

I used this to:

a) expand filesystem partition to fill the SD card.
b) set the hostname.
c) give minimal memory to the GPU (16MB).
d) enable SSH so I can run a headless server.

I’m not over-clocking at this stage but I may try that in the future if performance is poor.

Web Server: Lighttpd

At first I used Apache for the web server and it worked fine but I then tried the light-weight lighttpd and that worked equally well. So I’ll stick with that to get the most from my Pi.

sudo apt-get install lighttpd

At this stage you can access a test web page by browsing to the IP address of your pi. e.g.
This test page can be found at /var/www/index.lighttpd.html

Because /var/www is owned by root you would have to use sudo every time you make changes and other programs may also have problems. So the simplest option is to change the owner of the folder and all its contents to you (pi in this case):

cd /var/www
sudo chown pi: .
sudo chown pi: *

Scripting language: I’m using PHP to enable my site to be interactive.

Here I install the required PHP modules, enable the web server to handle PHP scripts and then restart the web server service.

sudo apt-get install php-common php-cgi php
sudo lighty-enable-mod fastcgi-php
sudo service lighttpd force-reload

I can now test this by putting some PHP code into /var/www/test.php and then browsing to it. e.g.

Database: MySQL is a standard option, I may try lighter-weight alternatives in the future.

sudo apt-get install php-mysql

During installation you will be prompted to create a MySQL admin password.

I now have a functioning web server and I can tinker with HTML and PHP files in the /var/www folder and view the results with my browser from any computer on my home network. This is great for learning but before I make my website public I’d like it to look a lot better.
I’ll take a break now and continue next time with setting up a CMS (a Content Management System).

Categorised as: Raspberry Pi Web Server

Comments are disabled on this post

Comments are closed.