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.

Drupal 8.8 and Later:

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

Prior to Drupal 8.8:

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