Asa Drupal developer, I need to run local copies of a bunch of different web sites. I might switch between a few clients any given day, and I might spin up another site to test a patch to Drupal core or to a contributed module.
I want to keep this short, so I will not go into all the different methods I have tried for setting up local sites. Let’s just say that all the Cool Kids have been using Docker for a few years now, and I have been slow to join the party.
The good news is that it is now really easy to get started with Docker, thanks to the Lando project. This post is the first in a series of short tutorials on using Docker and Lando to set up a local Drupal site. The immediate goal is to get to the Drupal installation screen.
Sorry, this is only going to work if you have a fairly new computer. According to the Lando documentation you will need one of
- macOS 10.10+
- Windows 10 Pro+ (or equivalent) with Hyper-V running
- Linux (with kernel version 4.x or higher)
So far, I have tested only with macOS 10.13 (High Sierra).
It is not strictly a requirement, but if you are not comfortable using the command line, then this tutorial is probably not for you.
Install Docker and Lando
Head over to the Lando releases on GitHub and download the latest package for your OS.
Run the installer. At least on a Mac, this installs Lando along with Docker for Mac. You can also install Docker first.
I wanted to make sure I had the latest versions for this post, so I
- Installed the latest stable version of Docker for Mac (17.12.0-ce-mac55 (Version 18.03.0-ce-mac60 (23751)))
- Reset Docker for Mac (Preferences, Reset, “Reset to factory defaults”)
- Installed the latest version of Lando (v3.0.0-beta.39)
- During installation, chose the “Custom” option to install just Lando, not Docker
There are a lot of ways to get the Drupal codebase. For this tutorial, let’s follow the official instructions: Installing Drupal 8. (See “Step 1: Get the Code”.) From Download & Extend follow the link to the release page for the latest version and download the tarball. As of this writing, the latest version is 8.5.1. I choose to save the tarball in
/tmp. If you save it somewhere else or get a newer version, then adjust the instructions in the next section.
Open up a terminal window. The following commands extract the tarball, creating the directory
Sites/drupal-lando/ inside your home directory. (I assume you already have the
tar xzf /tmp/drupal-8.5.1.tar.gz
mv drupal-8.5.1 drupal-lando
Still working in the terminal window, let Lando create a minimal configuration file for you:
lando init --recipe drupal8 --webroot=. --name="drupal-lando"
You can also run
lando init interactively. I give the command this way to make sure that it is reproducible.
This produces the following YAML file
If you prefer, you can skip
lando init and just copy and paste that file directly.
What does this command do?
If you run
lando with no arguments, it will show you the available sub-commands. The one thing I do not like is that you have to be careful to get help for a sub-command:
lando init -- --help
You can use the short form
-h instead of
--help, but other variants will not work. For example,
lando --help init is the same as
lando --help, and
lando init --help acts like
lando init (running the sub-command instead of showing the help text).
Start your (Docker) engine!
In the terminal window, type
If it goes smoothly, Lando should start Docker, create two containers, and leave you with instructions something like this:
BOOMSHAKALAKA!!!Your app has started up correctly.
Here are some vitals: NAME drupal-lando
SERVICES appserver, database
APPSERVER URLS https://localhost:32772
If it does not go smoothly, try quitting and restarting Docker.
If everything worked, then you can visit your local site at http://drupal-lando.lndo.site. (You can also use the HTTPS version, although your browser should warn you about the untrusted SSL certificate.)
Since you are starting with an empty database, you will be redirected to http://drupal-lando.lndo.site/core/install.php:
Drupal installation screen
You can accept the defaults on the first couple of screens, but when you get to the database configuration, see what
lando info has to say:
So enter “drupal8” as the database name, database username, and database password. Then open up the “Advanced options” and enter “database” for the host.
Drupal database configuration
In a minute or two you should have a clean Drupal site, ready to go!
Welcome to Drupal