Drupal Development on a Raspberry Pi

It’s possible to develop Drupal websites on a Raspberry Pi, and the performance is pretty good considering the specs of this sub $75 computer.

While I expect no professional Drupal developers are using a Raspberry Pi as their primary development environment, everyone starts somewhere. If a computer like a Raspberry Pi is all someone has, they can begin a Drupal career and someday earn, at least, an hourly rate equal to the cost of a Raspberry Pi.

This post details the steps to install DDEV, Docker, and a Drupal 9 website. DDEV is an open source tool that makes it dead simple to get local PHP development environments up and running within minutes. You can follow the written steps and watch along with the video below.

NOTE: I wrote this post many months ago but decided not to publish it. Running Drupal via DDEV requires a 64-bit OS, and Raspberry Pi OS’s 64-bit version has been stuck in beta for a few years. In my experience, alternative 64-bit operating systems available for the Pi were not stable enough to recommend. Yesterday, the 64-bit version of Raspberry Pi OS was released. I successfully retested the installation steps in this post with the 64-bit OS. It’s time to publish.

Requirements

  • Raspberry Pi 400 or Pi 4 B with minimum of 4GB RAM
  • Micro SD
  • Desire to learn

The steps below will install DDEV, Docker and a Drupal 9 website.

64-bit OS

A 64 bit OS is required to install DDEV. Start by downloading a Raspberry Pi OS 64 image to a Micro SD with Imager. If you are not familiar with this process, you can learn more on the Raspberry Pi website.

Pi Imager now includes Raspberry Pi OS 64-bit

After booting your Pi with the new Micro SD, complete the setup process. Reboot the Pi.

Verify your packages are up to date.

sudo apt update
sudo apt upgrade

Install Docker and DDEV

Install Docker and docker-composer

sudo apt-get update && sudo apt-get install -y docker.io docker-compose

Update your permission to run Docker:

sudo usermod -aG docker $USER

Reboot:

sudo reboot

Verify Docker is running by running the hello-world app:

docker run hello-world

Install required packages:

sudo apt-get install libnss3-tools xdg-utils

Install DDEV using install script:

curl -LO https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh && bash install_ddev.sh

Verify DDEV is installed:

ddev --version

Configure Drupal 9 Website

Create folder for the Drupal website:

mkdir drupal9
cd drupal9

Configure and start DDEV:

ddev config --project-type=drupal9 --docroot=web --create-docroot
ddev start

Install Drupal and drush:

ddev composer create "drupal/recommended-project"
ddev composer require drush/drush
ddev drush site:install -y

Launch website as administrator:

ddev drush uli
ddev launch

Next Steps

USB SSD Drive – For faster, more reliable drive access, consider running your Pi from a USB SSD instead of the Micro SD card. You can find instructions for setting this us at Tom’ Hardware.

DDEV – If you new to DDEV, you learn more at DDEV-Local Documentation.

Reference Video

References

Watch: DDEV-Local on ARM64 Raspberry Pi

DDEV Drupal Quick Setup

DDEV and Mutagen on Apple M1

I’m a Linux desktop user and have been for three years. A driving reason for my switch from Mac to Linux was performance. As a LAMP stack web developer, using Docker-based tools for local development is a must. A nagging problem for developers is the performance of Docker on macOS, specifically file system performance. I share some performance comparisons in the January 2020 blog post, Faster Drupal Development on Linux.

On a recent episode of Talking Drupal, #318 DDEV, Randy Fay, the maintainer of DDEV talked about the DDEV’s recent addition of Mutagen. He claimed DDEV with Mutagen on Mac runs “almost as fast as native Linux.” I had to check it out.

Randy discussing DDEV implementation of Mutagen (5 minutes)

Testing Environment

I configure a newly acquired Mac with an existing Drupal project running locally with DDEV. I also installed this project on my Linux desktop.

  • Mac mini (M1, 2020) – 8GB RAM – 250GB SSD – macOS BigSur 11.5.2
  • Linux desktop – AMD Ryzen 9 3900x – 16GB RAM – 1TB M2 – Pop!_OS 21.04

Testing Process

I followed the steps below with Mutagen turned on and off and ran the test multiple times to verify the results were consistent. I followed the same steps on Linux without Mutagen.

ddev stop --remove-data
ddev poweroff
(set mutagen on or off)
ddev auth ssh
ddev start
ddev mutagen status
rm -rf vendor
time ddev composer install --no-cache 

Results

DDEV without Mutagen on Mac:
composer install --no-cache - 4:41.91 total 
DDEV with Mutagen ddev on Mac:
composer install --no-cache - 16.602 total
DDEV without Mutagen on Linux:
composer install --no-cache - 13.658 total 

Caveats and Conclusion

I only recently started using DDEV after listening to Randy on Talking Drupal, so my experience with it is not much more than conducting this experiment. However, I believe the testing process had enough controls to fairly evaluate a single action; composer install. If I’ve missed something here, I expect someone will let me know.

If you are a PHP developer using a Mac, the results of 4.5 minutes vs. 16.5 seconds demonstrate that DDEV with Mutagen should be evaluated as a local development environment. However, the Mutagen implementation is new and there are some caveats outlined in the Performance Documentation.

While I tested on Apple new M1, I would expect similar results from the Intel line of computers.

I’m glad to have been exposed to DDEV and its helpful community. I will continue exploring a switch to it, even in my Linux environment.

Drupal 9 and Lando

Overview

Below are steps to setup a local Drupal 9 composer based environment using Lando.

Prerequisites

You need to have Lando installed using these instructions.

Steps

Create a local folder. <app> will be the name of your application folder and Lando instance.

mkdir <app>

Position your working directory as your new folder

cd <app>

Initialize Lando and answer a few questions. This utility creates a .lando.yml file in your working directory. When you start Lando in the next step, this file is used to define the Lando configuration.

lando init
Choose: current working directory
Choose: Drupal9
Enter for webroot: web
Enter for app: <app>

Start Lando

lando start

Install Drupal code using composer. Note – Drupal is being install in a Docker container, not on your local computer.

lando composer create-project drupal/recommended-project blah -n

The above command uses composer to install Drupal and it’s dependencies into a folder called ‘blah’. Now, the files/folders in ‘blah’ will be move up one level into your directory and the ‘blah’ folder will be removed.

mv blah/* .
mv blah/.* .
rm -rf blah

Rebuild Lando containers.

lando rebuild -y

On a success rebuilt on Lando, it’s time to install Drupal 8. Goto the local URL for your Drupal 8 website.

https://<app>.lndo.site  

Follow the steps in the Drupal installation Wizard. When the database page appears, use ‘drupal9‘ for the database name, username and password. Also, use ‘database‘ for the host name (under the Advanced settings.

You should be up and running,

Moving to VIM

After 30 years in front of the keyboard, I decided to refine my craft and learn to touch type. It’s been about a month, and I’m improving. Keeping my fingers on “home keys” got me thinking about how often I remove them to touch the mouse. All these keys at my finger tips and they are almost useless for navigation within a file. Hello Vim.

I’ve used Vim for editing text files on a server for years. I knew the basics: insert mode, save, and exit. One of the powerful features of Vim is its modes. The two primary modes are Normal and Insert. When in normal mode, the keys are used to navigate, copy and paste, find, and much more. You don’t need to mouse or cursor keys; in fact, you shouldn’t be using them. To modify text, you enter insert mode, which is the only mode in most text editors. The capabilities of Vim are mind-blowing.

To get started, I watched several videos on Youtube and began a slow transition. While it’s a gradual transition, you will see the benefits quickly. I hope to replaced VS Code with Vim someday. I love the idea of using the same tool proficiently on a desktop, VPS, or Raspberry Pi.

How to get started

My recommendation:

  1. Vim Mode – using your existing IDE, such as VS Code, adding a Vim extension to give you basic Vim workflow and key bindings. This is a good bridge from where you are today to Vim 100%.
  2. Six Part Series – Recently, Youtuber, The Primeagan, released an excellent six part series to learn Vim. His videos are educational and entertaining. Watch video 1 and don’t moved to the second video until you don’t need to think about basic navigation keys. I’m not through them all yet.
  3. Explore – There are many Vim tutorial available online. You them to explore the capabilities of Vim to do things easier and faster.

Faster Drupal Development on Linux

Local Drupal development has moved to docker based environments with solutions like Lando and DDEv. With these tools, it’s fast and easy to spin up a local environment and manage many projects. The days of MAMP and WAMP are (long) gone.

Here’s the problem, Mac OS is the dominant development platform for Drupal developers, and Docker runs terribly on it. Docker interacts differently with macOS than it does with Linux. The source code on the host computer is shared with Docker containers. The multiple layers of communication between Docker and the macOS file system make file-sharing very slow. While Docker’s direct access to the Linux file system makes it very fast. This video, Improving Docker Desktop File Sharing Performance, from DockerCon 18 describes this issue in detail.

The file-sharing performance issue became apparent when working with a colleague to set up a new Drupal 8 website build. I was shocked to see the local build process taking over 8 minutes on my colleague’s computer and less than 30 seconds on my computer.

Benchmarks

In an unscientific way, with some help from my friends, I tested the build process on a few Macs and Linux computers with different hardware specs. Each computer had Docker and Lando installed. The website is a Drupal 8 Standard profile with Acquia’s BLT. The test is simple, run the BLT artifact build, blt artifact:build

Below are the results of this test.

ComputerSpecsOSArtifact:build
ThinkPad T420 (2011)i5 (2 cores), 8GB RAM, SSDLinux (Endevour OS)20 seconds
Custom Build (2020)Ryzen i7 (8 cores), 32GB, SSDLinux (Endevour OS)7 seconds
Macbook Air (2018)i5 (2 cores), 8GB RAM, SSDmacOS Catalina8+ minutes
MacBook Pro (2015)i7 (4 cores), 16GB RAM, SSDmacOS Mojave6 minutes

Solutions

There are some potential solutions. Lando has an undocumented Mac-only feature called “Turbo Mode”. Reviewing the issue thread, there are mixed results with this implementation. Turbo Mode had little impact on my test case shaving off 30 to 60 seconds. A 5% to 10% improvement is good, but when comparing it to performance on Linux, there is no practical improvement. Others have seen better improvements with Turbo Mode. This approach is easy to implement and worth exploring, but Turbo Mode hasn’t made it’s way into Lando as a supported feature. Use with caution.

Some tweaks can be made to your Docker configuration. Increasing the default RAM usage from 2GB to 4GB is a starting point. You can also limit the number of shared folders Docker watches, by default, the entire /Users folder is included. I tested the memory upgrade and limited the shared folders to only the necessary application folders. Similar to the results with Turbo Mode, they were minimal for my test case. You may have more promising results. There are many online resources with recommendations to improve performance, search “Docker Mac performance”.

The beauty of using Lando is simplicity, which starts to diminish with lots of OS based tweaks. I suspect more research and testing could result in better performance on Mac. BUT, using Linux for Drupal development with Docker will get you the best performance by far, with ease. It’s that simple.

Drupal 8 and Lando

Overview

Below are steps to setup a local Drupal 8 composer based environment using Lando.

Prerequisites

You need to have Lando installed using these instructions.

Steps

Create a local folder. <app> will be the name of your application folder and Lando instance.

mkdir <app>

Position your working directory as your new folder

cd <app>

Initialize Lando and answer a few questions. This utility creates a .lando.yml file in your working directory. When you start Lando in the next step, this file is used to define the Lando configuration.

lando init
Choose: current working directory
Choose: Drupal8
Enter for webroot: web
Enter for app: <app>

Start Lando

lando start

Install Drupal code using composer. Note – Drupal is being install in a Docker container, not on your local computer.

lando composer create-project drupal-composer/drupal-project:8.x-dev blah -n

The above command uses composer to install Drupal and it’s dependencies into a folder called ‘blah’. Now, the files/folders in ‘blah’ will be move up one level into your directory and the ‘blah’ folder will be removed.

mv blah/* .
mv blah/.* .
rm -rf blah

Rebuild Lando containers.

lando rebuild -y

On a success rebuilt on Lando, it’s time to install Drupal 8. Goto the local URL for your Drupal 8 website.

https://<app>.lndo.site  

Follow the steps in the Drupal installation Wizard. When the database page appears, use ‘drupal8’ for the database name, username and password. Also, use ‘database’ for the host name (under the Advanced settings.

You should be up and running,

Updates

12/10/2019 – As of Drupal 8.8.0, Composer project templates are now available as part of Drupal core. The composer create-project command was updated to reflect this change.

$100 Development Laptop

At the beginning of 2018 I switch to Linux as my ‘daily driver’. I have a desktop and laptop from System76 running Pop_OS!. I’m super happy about that switch.

Linux is everywhere; from Rasperry PIs to supercomputers. It runs nuclear submarines, refrigerators, air traffic control and my Drupal development environment. It can run fantastically on modern hardware and bring life back to the forgotten computer in the closet.

I wondered if it was possible to configure an under $300 laptop for Drupal development. I started by looking at low-end consumer laptops. Best Buy has Intel and AMD laptops, 4-8GBs Ram with an SSD, preinstalled with Windows, on sale in that price range. I asked for recommendations in an online Linux community. I was advised by many not to buy consumer ‘junk’, but instead, look for used enterprise-class laptops on Ebay in the same price range or less. In my research, I found a cult-like following for the Thinkpad T420, a laptop released in 2011 (see video The $110 Lenovo Thinkpad T420, a Laptop with a Legacy). It’s known for its durability, performance and ‘old-school’ keyboard. That seemed like a reasonable place to start.

Acquisition

The price range on eBay for a T420 with an SSD was between $125 – $225. I found one without an HD (or SSD) or power cord. With those two essential parts missing, I was highest bigger at $45 (plus 12.97 shipping). This T420 has as i5-2520M @ 3.200GHz with 8GB Ram. I bought a 240GB SSD for $28.95 and power cord for $10.99. At worse case, this would be a failed $97.91 experiment.

ThinkPad T420

You never know what you’re going to get with used equipment. The Thinkpad was in surprisingly good shape. As promised, everything was in working order with normal wear for a nine-year-old computer. I unboxed it, slid in the SSD and had Manjaro Linux installed in 10 minutes. Manjaro is my first experience with a Linux distribution outside of Pop_OS!.

Infamous Linux Wifi Issue?

I had one hiccup, the wireless card wouldn’t work. It wasn’t a big problem because the T420 has lots of ports, one of which is ethernet (take that Apple). I tried to get wireless working late into the evening, then decided to install the distribution I was familiar with, maybe it was a software issue. I installed POP_OS! and immediately identified the issue from a message, something like “wireless hardware switch is off”. What!!?? Sure enough, there’s a small hardware switch on the side of the T420 to turn off blue tooth and wireless. This problem was undoubtedly not software or hardware related. I decided to leave Pop_OS! running, I will experiment with Manjaro at another time.

Wifi Hardware Swtich

Drupal Development

The primary software requirements for my Drupal development includes web browsers (Chrome and Firefox), Lando (and required software) and VS Code (IDE). While there are many other tools I use day to day, those are the must-haves. Outside of Docker needing some extra attention, loading this software was straight forward. I’m was up and running in short order.

Observations

After a month of using the T420 as a second laptop for Drupal development and general computing tasks, my observations are:

  • The Thinkpad T420 is a solid computer. It feels and is a quality build.
  • I like the feel of the classic, “clicky clack” keyboard. It’s easy to use.
  • I missed a laptop with lots of ports and single purpose buttons
  • This computer is fast, not just fast enough. While I didn’t push the limit with lots of containers running at the same time I’m editing audio on a Zoom call, it performs well.

Summary

This T420 running Linux is at least a solid backup computer, and maybe a daily driver for most developers. It feels good to sit behind a classic laptop, running a current OS, while building a modern website. Maybe it’s like cruising down the road in a 1964 Mustang. Is it a fluke that I was able to put this system together for under $100? No. I’ve bought two more and have done the same thing.

Backstop JS and Lando

I’ve recently started using Backstop JS for visual regression testing. You can add the following settings to your Lando configuration, .lando.yml, to include Backstop JS.

services:
   node:
     type: node:10
     globals:
       backstopjs: "latest"
     command: npm start
     run_as_root:
       - apt-get -y update && apt-get -y install software-properties-common
       - wget https://dl-ssl.google.com/linux/linux_signing_key.pub && apt-key add linux_signing_key.pub
       - add-apt-repository "deb http://dl.google.com/linux/chrome/deb/ stable main"
       - apt-get -y update && apt-get -y install google-chrome-stable
 tooling:
   backstop:
     service: node

You will need to use the .internal URL from Lando to access the local website. For example:

  "scenarios": [
    {
      "label": "Homepage",
      "url": "http://appserver_nginx.your-site-name.internal"
    }

The backstop commands will be run through Lando tooling:

lando backstop reference
lando backstop test