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:
git clone --branch 8.6.x https://git.drupal.org/project/drupal.git drupal-lando-git cd drupal-lando-git
Optionally, check out a specific version. As of today, the latest release is 8.6.1:
git checkout 8.6.1
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
Install dependencies with composer
in the “Installing Drupal 8” guide.
composer install -o --no-dev
-o option tells
composer to generate optimized autoload files.
--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.
Normally, I would run
lando init interactively, but for the sake of
copy-and-paste, you can use
lando init --recipe drupal8 --webroot=. --name="drupal-lando-git"
Alternatively, just create
.lando.yml with these lines:
name: drupal-lando-git recipe: drupal8 config: webroot: .
Start Lando with
If all goes well, you should get a message like this:
BOOMSHAKALAKA!!! Your app has started up correctly. Here are some vitals: NAME drupallandogit LOCATION /Users/bfisher/Sites/drupal-lando-git SERVICES appserver, database APPSERVER URLS https://localhost:32772 http://localhost:32773 http://drupallandogit.lndo.site https://drupallandogit.lndo.site
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:
- Database username:
- Database password:
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
Assuming that you already have PHP and
composer installed, you can install
Drupal in the directory
lando-drupal-composer following the instructions there:
composer create-project drupal-composer/drupal-project:8.x-dev lando-drupal-composer --stability dev --no-interaction
This command creates your project in the directory
It creates the document root in the
web/ subdirectory: that is where to look
core/ subdirectory, and so on.
It also installs Drush, Drupal Console, and a few other projects for you, and
it takes care of running
After that, change to the new directory and initialize Lando:
cd lando-drupal-composer lando init --recipe drupal8 --webroot=web --name="drupal-lando-composer" lando start
The only differences here are the
--name option and
Here is the generated
name: drupal-lando-composer recipe: drupal8 config: webroot: web
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
You can add a command-line option when running
lando init --recipe drupal8 --webroot=docroot --name="drupal-lando-acquia"
or you can edit the generated file:
name: drupal-lando-acquia recipe: drupal8 config: webroot: docroot
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
.lando.yml) and then you can import it with
lando db-import ENV-SITE-DATESTAMP.sql.gz
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
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.
pantheon recipe has two advantages:
- The local environment matches Pantheon’s: nginx, mariadb, redis, etc.
- 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:
lando init pantheon --destination=mysite --pantheon-auth=TOKEN --pantheon-site=mysite --name=mysite cd mysite
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,
.lando.yml something like this:
name: mysite recipe: pantheon config: php: '7.1' webroot: web framework: drupal8 site: mysite id: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
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['trusted_host_patterns'] = '\.lndo\.site$';
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
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,
lando terminus auth:login --machine-token=t0Rj1g5DHGOBm8an9jWHGKYA8uqSGzGpbXgS49axPyjtI lando pull --code=none --database=dev --files=dev
(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
pull sub-command, there are several others for working with
Pantheon. (I have edited out the generic commands from this output.)
$ lando Usage: lando <command> [args] [options] [-- global options] Commands: pull Pull code, database and/or files from Pantheon push Push code, database and/or files to Pantheon redis-cli Run redis-cli commands switch <env> Switch to a different multidev environment terminus Run terminus commands varnishadm Run varnishadm commands Global Options: --help, -h Show help --verbose, -v, -vv, -vvv, -vvvv Change verbosity of output You need at least one command before moving on
Want to learn more?
Thinking about making the migration to Drupal 8? Already on Drupal 8 but don’t know how to fully leverage your site?
Check out Isovera’s workshops and custom training page! We’ve worked with organizations with large teams hoping to understand what’s new in Drupal 8 to small groups interested in enhancing frontend performance, and all sorts of teams in between! Visit our training page today to see how we can enable you!