Build it Your way With Lando, Docker, and Drupal

My first post in this series, Getting started with Lando, Docker, and Drupal, I explained my favorite method to download and install Drupal locally. I will not repeat the system requirements and how to install Docker and Lando, so check that post if needed.

Same disclaimer as last time:

It is not strictly a requirement, but if you are not comfortable using the command line, then this tutorial is probably not for you.

Now I want to explain what changes depending on how you install Drupal. The earlier post downloads a tarball, and it is not much different if you use a zip file instead. Read on for details on the following methods:

  • Use the official Drupal git repository.
  • Install Drupal with composer.
  • Run a local copy of a site hosted on Acquia.
  • Run a local copy of a site hosted on Pantheon.

Use the official Drupal git repository

Get the code

Download the git repository for Drupal core. If you visit the project page for Drupal core, then you can find the git URL on the “Version control” tab, same as for any other project (module, theme, other) hosted on drupal.org:

Optionally, check out a specific version. As of today, the latest release is 8.6.1:

Install dependencies

Since version 8.3, Drupal’s git repository does not commit Symfony and other packages on which it depends. You have to install them using composer: see Install dependencies with composer in the “Installing Drupal 8” guide.

The -o option tells composer to generate optimized autoload files.

The --no-dev option means that composer should not install development packages, such as PHPUnit. I would not actually use that option for a local installation, but I am afraid that someone will copy and paste my command when installing on a production site, where some of the development packages create a security hole.

Initialize Lando

Normally, I would run lando init interactively, but for the sake of copy-and-paste, you can use

Alternatively, just create .lando.yml with these lines:

Install Drupal

Start Lando with

If all goes well, you should get a message like this:

Then you can visit http://drupallandogit.lndo.site and install Drupal as usual.

Now that Drupal 8.6 has been released, we can choose the Umami installation profile:

As explained in the previous post, lando info will tell you what to fill in for the database credentials:

  • Database name: drupal8
  • Database username: drupal8
  • Database password: drupal8
  • Host: database (under “Advanced options”)

Since I chose the Umami installation profile, it takes a little longer than usual, but in a few minutes we get our reward:

Install Drupal with composer

There are a few ways to manage a Drupal site using composer described on Using Composer to manage Drupal site dependencies. Although not officially supported by the Drupal project, the standard method is to use the Composer template for Drupal projects, also known as drupal-composer/drupal-project.

Assuming that you already have PHP and composer installed, you can install Drupal in the directory lando-drupal-composer following the instructions there:

This command creates your project in the directory lando-drupal-composer/. It creates the document root in the web/ subdirectory: that is where to look for index.php, the core/ subdirectory, and so on. It also installs Drush, Drupal Console, and a few other projects for you, and it takes care of running composer install.

After that, change to the new directory and initialize Lando:

The only differences here are the --name option and --webroot=web. Here is the generated .lando.yml:

Now you can visit http://drupallandocomposer.lndo.site and install Drupal.

Run a local copy of a site hosted on Acquia

Acquia does not provide any special support for Lando, but if you are using Acquia’s BLT system, then see Lando’s blog post and BLT docs on Lando for how to set up BLT with Lando as the local dev environment.

For this post, here are some basics:

Acquia uses docroot as the web root

Sites hosted on Acquia use docroot/ as the web root, so you should specify this when creating .lando.yml. You can add a command-line option when running lando init:

or you can edit the generated file:

Importing the database

This is not specific to Acquia, but this is the first time I have talked about using Lando to make a local version of an existing site, so what about the database?

Using the Acquia dashboard or some other means, you can download a database backup. Save it in the main directory of your local site (the same directory as .lando.yml) and then you can import it with

This will drop all tables in the existing database before importing from the backup. If, for some reason, you do not want to drop the existing tables, then you can add the --no-wipe option.

Run a local copy of a site hosted on Pantheon

Lando has a recipe customized for Pantheon. See Working with Pantheon in the Lando documentation for details.

Using the pantheon recipe has two advantages:

  1. The local environment matches Pantheon’s: nginx, mariadb, redis, etc.
  2. You get additional Lando sub-commands for working with your Pantheon site.

Initialize your site with “lando init pantheon”

Unlike the other methods, there is magic in the lando init pantheon command that is not captured in .lando.yml, so actually run this command:

Or at least run lando init pantheon (NOT ... --recipe=pantheon) and supply the rest interactively.

If you do not already have a token, then see Creating and Revoking Machine Tokens in the Pantheon documentation.

This command will create mysite/ as a subdirectory of the current directory, with a .lando.ymlsomething like this:

Start the site

Before going any further, start your Docker containers with lando start and visit your site. Note that, after lando init pantheon, I already changed to the new directory.

When testing for this blog post, I got an error because of Trusted Host settings. I added this line to settings.php:

If you have configured settings.php to include a local settings file, then that is the right place to add this line.

Get all the things

The pantheon recipe supplies a lando pull sub-command. You can use it to pull the code, database, and files from any of your Pantheon environments (“dev”, “test”, or “live”). You can also specify “none” to skip any of these.

For example, to skip the code (since we just did a git clone) and get the files and database from the dev environment,

(I may have done something wrong, because I had to re-authenticate.)

Alternatively, just use lando pull and supply the values interactively.

Other Lando sub-commands

Besides the pull sub-command, there are several others for working with Pantheon. (I have edited out the generic commands from this output.)