Drupal and the Raspberry Pi

November 6, 2015
acquia robot and raspberry pi

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.

Raspberry Pi Dramble

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

Install Ansible with apt-get

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 ~ $):

Ansible version

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 Pi Ansible playbook complete

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).

Drupal 8 installed and running on Raspberry Pi

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:

  1. Drupal Pi on GitHub
  2. Raspberry Pi Dramble project
  3. Ansible for DevOps

Sign-up for our Developer Blog Newsletter


Add comment


Thanks for this post. I now have Drupal installed on my Raspberry Pi2.
Now, how can I use ssh for a remote access ?

ssh pi@192.168.xxx.xxx
Permission denied (publicly).

The geerlingguy.security role that runs locks down SSH access so only users with public keys already configured in the `pi` account (or any other configured user account on Raspbian) can log in. You can go on the Pi itself, log in, and edit the SSH configuration to turn on password authentication again: https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2

It's best (especially if the Pi is on any kind of public or large private network) to use keys, and also set a secure password for the `pi` account (or any admin account on the pi).

Thanks for the article.
Once the installation is done, which users can be used ?
I can "create a new account" but is the admin user ?

The admin username and password are configured in your `config.yml` file, and set once when the Drupal 8 site is set up. You can then log into that account and create other Drupal accounts on the site.

I'm getting failures at the TASK: Generate Drupal site with drush makefile, and the recap errors with "could not create retry file."

Any ideas on what this is/how to fix it?

Time to debug now. ran the prescripted commands but ended up with a simple "Welcome to nginx on Debian" so some of the config hasn't been done.

I tried this on my up-to-date pi3, and unfortunately just get the "welcome to nginx" page. I subsequently attempted to roll back/uninstall all the changes/roles and repeated -- with the same result

Any obvious ideas? The tasks all appear to run successfully

I want to use this copy of Drupal as a "stick in my bag and take to work" copy. I can't be tweaking the hosts file on my desktop at work all the time to follow the dhcp address the Raspberry PI will get.

I can see in the config.yml the following setting:

drupal_site_redirect_uri: "drupalpi.dev"

Can this be changed / removed ?

The step to ensure that PHP packages are installed is failing. Any clue?

so i keep getting an error in the last second of the "ansible-playbook -i inventory -c local main.yml" step.

If updated the requirements.yml to reflect the update on the issues tab at the github. Still getting this error below.


TASK [geerlingguy.php : Ensure PHP packages are installed.] ********************
failed: [] (item=[u'php7.0-common', u'php7.0-cli', u'php7.0-dev', u'php7.0-fpm', u'libpcre3-dev', u'php7.0-gd', u'php7.0-curl', u'php7.0-imap', u'php7.0-json', u'php7.0-opcache', u'php7.0-xml', u'php7.0-mbstring', u'php-sqlite3', u'php-apcu']) => {"failed": true, "item": ["php7.0-common", "php7.0-cli", "php7.0-dev", "php7.0-fpm", "libpcre3-dev", "php7.0-gd", "php7.0-curl", "php7.0-imap", "php7.0-json", "php7.0-opcache", "php7.0-xml", "php7.0-mbstring", "php-sqlite3", "php-apcu"], "msg": "No package matching 'php7.0-common' is available"}

RUNNING HANDLER [geerlingguy.firewall : restart firewall] **********************

RUNNING HANDLER [geerlingguy.nginx : reload nginx] *****************************

RUNNING HANDLER [geerlingguy.mysql : restart mysql] ****************************
to retry, use: --limit @main.retry

PLAY RECAP ********************************************************************* : ok=58 changed=21 unreachable=0 failed=1

Dear All,
I do have the same error... Is there any solution for this?

Kind Regards,
Oele Geirnaert

Thanks Jeff
Awesome piece of work - not tried it yet and am working on my first Pi to run Kodi. This will certainly be my next project.

If you get an error on the ansible install, complaining about libffi, you need to "sudo apt-get install libffi-dev"

Thank you for all of your work. I was able to install Drupal 8 on my Raspberry Pi 2 however I can only access the site using If I try http://localhost or the IP address, I am redirected to www.drupalpi.dev with a "site can't be reached" error. The same thing happens when I use a remote PC on the same network and try to connect to the IP address of the Pi. Any help would be greatly appreciated.

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-bQgrX9/pynacl/