Skip to main content

Lando: a docker CLI to setup a local environment for Drupal

Develop your Drupal website in local using Lando

Setting up a local environment for Drupal development can be a tedious task, requiring hours of work, especially when dealing with the intricacies of manually configuring web servers and databases in environments that are not Unix. 

Traditional methods such as using Nginx or LAMPP (Linux, Apache, MySQL, PHP) often require detailed configuration and can be time-consuming. 

However, using Docker and Lando simplifies the process by providing a standardized, containerized environment that is easy to manage and replicate in different environments.

Requirements

Docker: Docker is a platform that allows you to create, deploy, and run applications in containers.  Download and install Docker Desktop or Docker for Linux.

Lando: Lando is a local development environment and DevOps tool built on Docker, designed to simplify the process of creating local development environments.

Advantages of Using Docker and Lando

  • Consistency: Ensures that your development environment is consistent across different machines and developers as you can choose from the configuration files the Drupal and PHP versions for the environment.
  • Isolation: Each project runs in its container, avoiding conflicts between different project dependencies. For the database, the system creates a specific volume in which they store the local data. Lando offers a CLI to export and import Database dumps in just a few seconds.
  • Simplicity: Simplifies complex setups with pre-configured services, reducing the need for manual configuration. Developers can save in GIT and upload to a remote repository all their lando configurations.
  • Portability: Containers can be easily shared and replicated, making it easy to set up the same environment on multiple machines. You can create GIT pipelines that deploy automatically your Drupal application automatically to servers without doing manual deployment tasks.
     

First Step: Install Lando

Download and install Lando following the instructions on their website: lando.dev, which requires Docker already installed.

In the case of Windows environment using WSL 2:

  1. Docker has to be installed on the main Windows machine, choosing the WSL as the virtualization engine. You can choose during the Docker installation or from the Docker configuration.
  2. Lando must be installed inside the WSL following the CURL command in their website, and docker must be running in the main machine to complete the installation.

This will allow you to develop inside the WSL using Visual Studio and Linux environment and run all the CLI commands from the WSL.

 

Second Step: Create a new Lando Project

1. Initialize a Lando project:

Open your terminal or command prompt and navigate to the directory where you want to create your Drupal project. Run the following command to initialize a new Lando project:

  lando init

 

2. Select a recipe:

Lando will prompt you to select a recipe. Choose the "Drupal 10" recipe for a Drupal 10 project or "Drupal 10" for a Drupal 8 project.

3. Configure your project:

Follow the prompts to configure your project. Lando will ask for the name of your project and the location of your codebase. If you don't have an existing Drupal codebase, you can let Lando download it for you.

 

Third Step: Configure Lando Services

1. Edit the .lando.yml file:

Lando creates a `.lando.yml` file in your project directory. This file defines the services and tooling for your project. Open this file in a text editor and ensure it includes the necessary configurations for Drupal, such as database, web server, and additional tools.
 

name: my-drupal-site
recipe: drupal10
config:
  webroot: /web
 Lando automatically will choose the PHP version for Drupal 10 and you will have installed Composer and drush CLI.

In case you change the configuration in the lando config you must run:

lando rebuild -y

to recreate the docker-compose configuration you will use when you will start Lando.

 

Fourth Step: Start Your Lando Environment

1. Start Lando:

Navigate to your project directory in the terminal and start Lando with the following command:

lando start

Lando will download and build the necessary Docker images, and then start the containers for your project.

2. Access your site:

Once Lando has started, it will provide you with URLs to access your site and services. Typically, your Drupal site will be available at `http://my-drupal-site.lndo.site`.


Fifth Step: Install Drupal

1. Install Drupal:

 

Open the provided URL in your browser to access the Drupal installation page. Follow the on-screen instructions to complete the installation process. Lando will provide the database connection details required during the installation.

 

The main database credentials for Drupal 10 recipe are:

 

username: drupal10
password: drupal10
Database: drupal10
hostname: mysql

 

Sixt Step: Use Lando Tooling

1. Run Drupal commands:

 

Lando comes with pre-configured tools for Drupal, such as Drush and Composer. You can run these commands directly in the terminal within your project directory. For example, to clear the Drupal cache, use:

 

lando drush cr

2. Composer:

 

To install a new Drupal module using Composer, use:

 

lando composer require drupal/devel

Conclusion

Using Docker and Lando to set up a local Drupal development environment allows you to start faster your development activities, offering a consistent and isolated environment that is easy to replicate and share. 

 

This approach not only saves time but also minimizes the risk of configuration errors, allowing you to focus on development rather than setup. 

 

This approach has been used by our Geonovation Team to work for our customer projects.

 

Now that you already have your Drupal environment configured, you can proceed to set up and configure your Drupal theme using Bootstrap following this tutorial.

 

MODERNIZE YOUR DIGITAL PRESENCE

Get in touch with us by filling out the form. Our PM will contact you within 24 hours, and we'll sign an NDA if you require it. Our expert team will then efficiently evaluate your project requirements and strategize for success.

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.