The Rasp Pi serves up a tempting web server

Lead Image © Geoff Leighly,

At Your Service!

The Raspberry Pi is a great web development tool for building home web servers, allowing you to experiment with Linux packages and test scripts locally before moving them to a production server.

For those of you who have websites located on a shared (or cloud) hosting account without shell access, the Raspberry Pi can help you unleash some of the power that comes with a virtual private server (VPS) or dedicated web hosting package by giving you shell access and full control, in terms of packages and custom configuration. This concept alone makes it valuable to web designers or developers.

For example, most hosting companies use PHP in "safe mode," but you can set up a Rasp Pi to run PHP with safe mode off. (Website security should not be handled at the PHP level, and because its ability to secure a website is largely illusory, safe_mode has been discontinued in PHP v5.4.0 [1].)

With safe mode off, you can use various functions (e.g., exec, passthru, shell_exec, and fopen) that let you run shell commands from PHP scripts and create files on the fly.

The shell_exec and exec functions allow you to use PHP and the Linux command line in one go, bestowing many advantages, such as custom pages based on logfile data and automatic screenshots of websites, courtesy of the Linux package wkhtmltopdf.

Although the Raspberry Pi might be not be the best option for hosting a website or blog with thousands of unique visitors each month or with a hundred active email accounts sending and receiving thousands of messages a day, to start, it is a very good place to host a small website that does not receive tons of traffic.

In the beginning, small startup companies generally do not receive lots of traffic, nor are many of them willing to spend the money to fund a well-targeted Google AdWords campaign to acquire instant traffic. With that in mind, the Rasp Pi is a valid starting point for hosting a website, because you can easily migrate to another server at a future date when the need arises.

Because the Raspberry Pi is nice and small, it is easy to connect one or more of them to your router to provide a resource for hosting websites – especially if they are built with efficiency in mind.

Additionally, the Rasp Pi is a great device for gathering remote data (e.g., live web cams and weather stations) that can be delivered to another host. You may find that the Raspberry Pi is such a good device for your web server experiments that you end up hooking several of them to unused ports in your router.

For an experienced web developer or administrator, the whole exercise of building a personally configured server could probably be completed within an hour, in the absence of any network hangups or other unforeseen problems. This time frame can help a non-experienced user know what to shoot for in terms of efficiency.

In this article, I will show you how to get your website up and running and how to set it up so that it can be found via the domain name (or IP address). I also explore many setup and configuration possibilities that you might want to try to get the most out of your hardware on an everyday Internet connection.

The examples in this article assume you have you have installed Raspbian as your operating system.

Getting Started

To get the project rolling, all you need is a booted Rasp Pi configured with SSH enabled. If you did not enable it when you installed Raspbian, you can run sudo raspi-config (Figure 1) and enable it in Advanced Options  | SSH (Figure 2).

Figure 1: Enabling SSH in raspi-config.
Figure 2: Your web server is working.

Although you can hook up everything to your high-definition television as a monitor and run the terminal to install the required packages, you can also use any other computer on your local network to access your Rasp Pi through SSH. If you plan to access the Rasp Pi from outside your local network, then you absolutely need SSH enabled. If you are set on using the Rasp Pi as its own device without SSH, you will need a compatible keyboard and mouse.

Furthermore, if you plan to use more than one Rasp Pi (e.g., a Rasp Pi for backups), SSH allows you to connect to the main Raspberry Pi from any Internet connection, from which you can then connect to any other Raspberry Pi on the local network. In simpler terms, having access to all Raspberry Pis connected to the home router makes it simple to operate everything from anywhere.

SSH Basics

Two common methods for connecting with your Raspberry Pi via SSH are to use a terminal in Linux or an SSH client like PuTTY [2] on any of the major operating systems. Although they both make SSH connections that allow you to create, open, modify, and save files easily, they do have connection and usage differences. For example, on Ubuntu, you use the command

ssh -p 22

whereas with PuTTY, you just add the hostname and click Open.

Some users prefer using the terminal because it has excellent copy, paste, and command history capabilities, and you can open multiple terminals at once.

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content