We have tons of crazy ideas here at Codeable and one of them actually became a reality; We thought to ourselves, what if the client could receive a physical copy of their site after the development has been done? Granted, a developer could just give them a copy on a USB key, but that wouldn’t be much fun, would it?

That’s why we decided to try and set up WordPress on the Raspberry Pi a $46-ish computer, primarily used for educational purposes but widely (ab)used all over the world, by geeks like us.

Note: This is just an experiment and you shouldn’t use Raspberry Pi to host your production WordPress site. But if you want to impress your client (and earn infinite bragging power), read on. No Raspberry Pis were harmed during this experiment.

What you need

Because Pi comes barebone, you’ll have to buy (or borrow or dig out of your closet) these things:

  • MicroSD card (8+ GB is recommended)
  • MicroSD reader or adapter (so you can plug it in your computer)
  • USB Keyboard
  • USB Mouse (optional, if you want to use graphical interface)
  • Micro USB power adapter
  • HDMI cable
  • HDMI-compatible monitor or TV
  • Ethernet cable
  • A free ethernet port on your router
WordPress RaspberryPi components
The ingredients - I didn't have any lying around :)

As I didn’t have most of the components, some shopping was in order, but apart from the Raspberry Pi, those are a one-off purchase. The total amount of those components was $66 (€61).

Step 1: Set up MicroSD card

Note: The instructions for this step are written for Mac, simply because I don’t own any other computer. If you use Windows, follow these instructions. For more tech-savvy readers, this page provides even more useful information.

After you insert the MicroSD card into your reader or adapter and connect it to the computer, visit the Raspberry Pi downloads page. There are several operating system images there, but I recommend you choose the Raspbian, because it’s the most extensively tested and thus more likely to work out of the box. Initiate the download (which may take a while, depending on your internet bandwidth) and while you’re waiting, open Disk Utility App.

There, locate your MicroSD, and format it by clicking Erase. This should only take a couple of seconds and once done, close the Disk Utility - you won’t need it anymore.

Next, open your terminal and run the following command:

$ diskutil list

This will show you all the disks (including flash cards), which will usually start with /dev/diskX (X being a number). The easies way to locate your MicroSD is the one whose type is DOS_FAT_32 and corresponds to the size of it. In my case, that’s /dev/disk2/:

Diskutil list screenshot
The list of disks and cards

Before we can set it up with the operating system, we need to unmount it (don’t worry if you don’t know what it means - it has the same effect as when you click the eject icon on a disk image in finder):

$ sudo diskutil unmount /dev/disk2s1

By now your download should have completed, so extract the contents of the zip file into your desktop. It only has one file in it, in my case it was 2015-02-16-raspbian-wheezy.img. To create a boot disk from that file, run the following commands:

$ cd ~/Desktop
$ sudo dd bs=1m if=2015-02-16-raspbian-wheezy.img of=/dev/disk2

Warning: Make sure that you enter the correct disk number, otherwise you risk of overwriting your primary disk, rendering it unusable. You’ve been warned!

This may take a couple of minutes, and once it’s done, it’ll mount your MicroSD so you can locate it in the Finder and inspect it’s contents. If you see a bunch of awkwardly named files it means the process was successful and you can eject the card, remove it from the reader and insert it into your Raspberry Pi, which has been silently, patently waiting for your attention. Time to give it some now :)

Step 2: Set up Raspberry Pi

Insert the MicroSD card in the slot/port and connect all the cables: HDMI, Keyboard, Mouse, Ethernet, and Micro USB power adapter as last (since Raspberry Pi has no power switch and we want to make sure everything is in order before powering it up).

After a bunch of lines that only Linus Torvalds understands a configuration screen will open with a bunch of options. You can safely ignore all of them - apart from one; If you want to access your Pi through Secure Shell, navigate (using arrow keys on the keyboard) to Advanced options and turn on SSH.

raspberry pi configuration
Raspberry Pi configuration screen

Step 3: Install WordPress dependencies

I’ve written about setting up a WordPress server before I’m just going to run the same commands to install the necessary packages (refer to the original article for details):

$ sudo apt-get update # update the repos
$ sudo apt-get dist-upgrade
$ sudo apt-get install -y php5-fpm php5-cli php5-gd php5-mysql mysql-server nginx unzip

(When mysql asks you for a password, just press enter, this is an experiment, so we don’t need one).

Before we reboot the Pi (we need to do so because we also updated the system packages), open MySQL ($ mysql -u root) and run the following commands to create the database, the user and grant the necessary permissions:

> CREATE DATABASE wppi;
> CREATE USER wppiuser@localhost IDENTIFIED BY "password";
> GRANT ALL PRIVILEGES ON wppi.* TO wppiuser@localhost;
> FLUSH PRIVILEGES;
> exit

Once done, reset the Raspberry Pi:

$ sudo reboot

Before we can install WordPress, we need to create a virtual host for Nginx, just run:

$ cd /etc/nginx/sites-available
$ sudo nano wordpress

and paste the following content in (remember the line 5):

server {
  server_name localhost;
  listen 80;

  root /home/pi/www/wordpress;
  index index.php index.html;

  location / {
    try_files $uri $uri/ /index.php?$args;
  }

  location ~ .php$ {
    try_files $uri /index.php;
    include fastcgi_params;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_index index.php;
  }
}

Then, delete the default virtual host, enable the one you have just created and restart Nginx for changes to take effect:

$ cd /etc/nginx/sites-enabled
$ sudo rm default
$ sudo ln -s ../sites-available/wordpress
$ sudo service nginx restart

Step 4: Download and install WordPress

Remember the line 5 of your virtual host? Time to download WordPress into that directory. As per our tutorial on installing WordPress these are the commands you need to run:

$ cd
$ mkdir www && cd www
$ wget https://wordpress.org/latest.zip
$ unzip latest.zip

a) install remotely

Now that everything is in place, you can install WordPress just like you would do it on a real server - access it through a browser on your computer. On Pi, enter:

$ ifconfig

This will give you the IP, which you then paste into your browser’s address input and proceed with the WordPress installation steps.

ifconfig result
Line 2 has your ip, note the inet addr:192.168.0.16

b) install locally

The second option is to install WordPress directly on Pi. To do so, you need to open the window manager (graphical user interface), by running the following command (make sure your USB mouse is plugged in):

$ startx

Once it opens up, click on the globe icon next to the menu (top left), which will open the Epiphany web browser. Here’ instead of the IP, you can use http://localhost to access your WordPress install.

Raspberry Pi WordPress TV
WordPress on the living room TV. Awesome! :)

Do you want one?

We decided we’ll give you a chance to win the very Raspberry Pi you’ve seen on the screenshots above (was used as the Guniea pig for this article) and in order to participate, all you have to do is tweet this:

What if you’d be able to give WordPress as a physical gift? With Raspberry Pi, you can. Click To Tweet

We’ll announce the winner on March 31st (because on April 1st no one would believe us).