For the past few years, I've been fascinated with credit card-sized budget computers, most especially the one that started the current revolution in hardware hacking, the Raspberry Pi.
I have owned every model Raspberry Pi: I have a network of Raspberry Pi A+ computers running an environment monitoring service in my house, and I have a couple Raspberry Pi B+ computers running different services on my local network. But I've been most interested in doing fun things with Drupal on Raspberry Pis.
Once the Raspberry Pi model 2 was released earlier this year—with an upgraded 4-core processor, and twice the RAM (a full Gigabyte!), I wanted to really test the limits of Raspberry Pi-based infrastructure. I bought six of the model 2 computers, along with a network switch, power supply, and chassis, and built myself the Pi Dramble—a cluster of Raspberry Pis running Drupal 8.
If you're interested in building your own 6-node Drupal 8 infrastructure using Raspberry Pis, I encourage you to check out the Raspberry Pi Dramble project on GitHub. There's a parts list, a guide for building a base microSD card image for all the servers, a guide for deploying Drupal to the Dramble, and even comprehensive benchmarks on Drupal, microSD cards, and networking!
But I don't expect most people to spend over $400 buying Pis and other accessories just for tinkering. That's why I also created the Drupal Pi project.
Building Your Own Drupal Server
There are hundreds of guides online for installing Drupal in a huge variety of environments, even on Raspberry Pis, but many of them take you step-by-step through command line instructions that are brittle and prone to breaking any time there are new Drupal versions, Raspberry Pi versions, Raspbian (the OS the Pi runs) versions, etc.
Instead of doing that, I'm going to introduce a way to install and run Drupal on your Raspberry Pi using Ansible and some open source Ansible roles that do everything in a more maintainable way. In fact, almost all of the code that is used to build the single Drupal Pi is shared with a ton of other projects that build Drupal servers, like Drupal VM, Pi Dramble, and the Drupal example from my book, Ansible for DevOps!
Acquiring the Raspberry Pi
First, of course, you will need a Raspberry Pi. Preferably a Raspberry Pi 2 model B, as it's the fastest Pi available. You need a Raspberry Pi, a micro-USB power adapter (with at least 1A of power), a microSD card (get at least 8 or 16GB so you have room to grow, and check out this list for recommendations!), and either a network cable (if you have wired networking), or a small USB WiFi adapter.
Once you have everything together, download a copy of Raspbian Jessie and write the downloaded image to your microSD card following the Raspberry Pi foundation's instructions for Installing Operating System Images.
Setting up the Raspberry Pi
Plug a monitor and keyboard into the Raspberry Pi, then plug in the micro USB power cable, and let the Raspberry Pi boot up into it's GUI environment.
Once it's booted, open the Terminal from the menu bar, and enter the following command to install Ansible:
sudo apt-get update && sudo apt-get install -y python-dev python-pip && sudo pip install ansible
It will take a few minutes for everything to be downloaded and installed via pip
(Pip is a package manager for Python, like Composer for PHP). If you have an older Raspberry Pi, then it could take 10-20 minutes to install Ansible.
Make sure Ansible is working and you have a version greater than 1.9 by running ansible --version
in the Terminal (when it comes back to the prompt, like pi@raspberrypi ~ $
):
Now that you have Ansible installed, you can download the Drupal Pi project and use it to get a proper LEMP stack and Drupal 8 running on your Raspberry Pi!
Installing Drupal with drupal-pi
First, clone the drupal-pi
project to your Pi:
git clone https://github.com/geerlingguy/drupal-pi.git && cd drupal-pi
Then copy the example configuration and inventory files to remove the example.
prefix:
cp example.config.yml config.yml && cp example.inventory inventory
Finally, install all the required Ansible roles for setup to complete:
sudo ansible-galaxy install -r requirements.yml
At this point, you're ready to install Drupal 8! The last command will run the entire Drupal Pi Ansible playbook, which will install and configure Nginx, PHP, and MySQL, then download and install Drupal 8:
ansible-playbook -i inventory -c local main.yml
Let this playbook run for a while (it will take at least ten minutes to complete), and at the end, you should see a screen like the following:
Drupal 8 should now be running on your Raspberry Pi, available over port 80. On your Raspberry Pi, you can either access http://localhost/ or a domain (if you set one up in your /etc/hosts
file). On another computer on your network, you can either access http://[IP-address-of-Pi]/ or a domain (if you set one up in your /etc/hosts
file).
Next Steps
After you get Drupal installed, you might have some questions like can the Raspberry Pi handle production levels of traffic? Or what kind of things can I do with Drupal 8 on a Raspberry Pi? We'll take a look at those questions and more in some upcoming blog posts!
Make sure to check out the following resources for more information about Drupal, Ansible, and Raspberry Pis: