Drupal

Lando for all our Drupal development environments

Published on 26 February 2021
Lando Drupal development environment
The team has widely adopted Lando to provide identical local development environments.

The challenge for a development team: working together

It's great, the team is growing. The team is expanding. Now, we can have more people on certain projects. OK, but how do we organize this? Working together without stepping on each other's toes, producing procedures while leaving flexibility to teams… that's the daily reality of every project team now. We need to take care of these organizational issues, listen to each other, and dedicate energy to it. In this situation, when a tool solves a problem with minimal effort, it becomes imperative to roll it out and require its use. That's what we did with Lando.

Lando?

Lando is an overlay for a Docker container. It makes life easier for our Drupal developer team. In just a few minutes, you have your local environment and, most importantly, you know all team members are working in the same conditions.

Lando allows you to: 

  • Easily have a local development environment.
  • Work in an identical environment to your colleagues who are on the same project.
  • Easily manage tricky configurations like SSL, SSH keys, and repetitive settings.

Simply put, Lando harmonizes relationships between developers, who often come from different backgrounds and use different local software configurations. It makes it easier to onboard and assist developers. It allows you to work on larger-scale projects.

Getting started with Lando

Start Lando

lando start

This command starts the application's container. You can then directly access the site via the URL provided by Lando (for example, http://my-site.lando.site). The first time, Lando will first build the container for the project.

Shut down Lando

lando stop

This command stops the application.

lando poweroff

This command shuts down all running Lando applications.

Tools to use in Lando:

lando composer        Runs composer commands
lando db-export [file]     Exports database from a service into a file
lando db-import      Imports a dump file into database service
lando drupal             Runs drupal console commands
lando drush              Runs drush commands
lando mysql              Drops into a MySQL shell on a database service
lando php                Runs php commands

For Drupal projects, we use and access all our usual tools and services inside the Lando container. We must always prefix the command we want to run with lando to execute it inside the container.

For example, to update Drupal, run these commands:

lando composer update drupal/core --with-dependencies
lando drush updb
lando drush cr 
Information about the container
lando info

Useful for seeing the local site URL or PhpMyAdmin, for example.

Accessing error logs:

lando logs

Tail logs:

lando logs -s appserver -f

Configuration: Landofile .lando.yml

The project's Git repository must include the Lando configuration file. This file tells Lando which services to install in the Docker container and, optionally, the versions of these services (Apache, Nginx, Solr, Varnish, PHP, MySQL, Node, PhpMyAdmin, etc.) If the Lando configuration changes (for example, if you want to change the PHP version), you'll need to rebuild the container with the command:

lando rebuild -y

Site installation example

Clone the lesiteweb.com project repo locally and go to the project directory:

git clone bluedrop@gitea.bluedrop.club:bluedrop/lesiteweb.git
cd lesiteweb
git checkout prod (or another branch)

Add a settings.php file for the site:

cp sites/settings-lando.php sites/default/settings.php

Retrieve the database from a dump on the server:

scp lesiteweb@bluedrop-www.bluedrop.club:~/database.sql.gz

Start Lando, Lando will automatically build the container:

lando start

Install Drupal dependencies:

lando composer install

Import the database:

lando db-import database.sql.gz

You can now open the site locally in your browser: https://lesiteweb.lndo.site

For example, you can build assets with Webpack like this:

cd themes/bluedrop/assets
lando npm i
lando npm run build

Resources: 
Read the Lando documentation.
Read the Docker documentation and a post on its installation.
Read the Docker Compose documentation.
Tip: Set up a Drupal 9 multisite in Lando.

Read more articles on Drupal