Operation Manual

Chapter 9: The Pi as a Web Server
Although the Pi is significantly less powerful than most devices you would find in a data centre, that doesnt mean that it cant
act as a useful server in a home or business environment. Despite a small amount of memory and relatively underpowered
processor, the Pis low power draw and silent running makes it a great choice for serving low-traffic simple pages to a local
network or even out onto the Internet.
A large proportion of modern web servers run a combination of Linux, Apache, MySQL and PHP—commonly referred to as a
LAMP stack. Linux provides the underlying operating system; MySQL the database back-end; Apache the web server; and
PHP a scripting language for dynamic pages. Using a LAMP-based server, you can run some quite complex packages ranging
from content management systems like WordPress to interactive forums like phpBB. All of this is possible with the Raspberry Pi,
so long as you dont expect performance similar to that of a powerful commercial server.
Web servers work best with plenty of memory. To ensure maximum performance, switch the Pi’s memory partitioning to a 224/32 MB split (see
Chapter 6, Configuring the Raspberry Pi”) and don’t run a graphical user interface (GUI) at the same time.
Installing a LAMP Stack
If youre running the recommended Debian distribution for the Raspberry Pi, youre already one-quarter of the way to having a
fully-operational LAMP stack—specifically, youve already got the Linux portion installed. The next step is to install the missing
components: Apache, MySQL and PHP. At the terminal or console, type the following commands to install these packages:
sudo apt-get update
sudo apt-get install apache2 php5 php5-mysql mysql-server
This will prompt the apt package manager (see Chapter 2, “Linux System Administration) to find a number of dependencies
required to get a fully-functional LAMP stack running (see Figure 9-1). These packages and their dependencies take up a lot of
room on the Pis SD card—around 113 MB in totalso if you havent resized the root partition on the SD card, turn to
Chapter 5, “Partition Management, for instructions on how to free up more space.
Installation of the full LAMP stack can take quite some time on the Pi. Dont panic if the system appears to freeze for a minute or
two; the installation should continue normally after. Partway through the installation process, MySQL will prompt you for a
password (see Figure 9-2). Make sure you pick a secure password, as this protects the MySQL databasewhich, depending
on what your web server is designed to do, can store user names, payment details and other personally identifiable information.
Also make sure you pick a password you can remember! Youll be asked to confirm the password—to check for typing errors
and then the installation will continue.
Figure 9-1: Installing the LAMP stack on Debian