Create a new Drupal 8 project in Lando

 

Lando is a great local development environment for Drupal and other PHP applications. It's basically a wrapper for Docker Compose that abstracts the stuff you want to configure for Drupal down to a single file.

The Composer Template for Drupal Projects is a starter kit for a composer built project that contains Drupal. When you download Drupal, you get a directory containing a composer file, and all the drupal code. With the Composer Template, you will get a project directory with the composer file, and Drupal will be downloaded within a subdirectory you'll use as the web root.

You will need lando and docker installed before following these instructions.



Here are the steps I take to create a new Drupal 8 project:

  1. Create new project directory

    (within ~/Sites, or where you keep your projects)
    mkdir newsite
  2. Initialize lando

    lando init

    (select drupal 8, follow instructions)

    lando start
  3. Create new drupal project w/ composer template

    lando composer create-project drupal-composer/drupal-project:8.x-dev drupal --stability dev --no-interaction --no-dev

    When in doubt, look this up on the github page.

    I set the directory to drupal and use --no-dev. If you have a CI system set up, you can install dev dependencies locally, and have the deployment skip them. Otherwise, I don't want to check them into the repo.

  4. Move stuff around

    mv .lando.yml drupal/
    mv drupal/ ../newsite_
    cd ..
    rm -rf newsite/
    mv newsite_/ newsite

    Why do I do this? The composer template won't let you create the project within the current directory. You could create the project with your local composer first, then initialize lando. In this way though, I'm using the lando environment to determine the dependencies it will be running, so the correct php version will be considered.



    What I'm doing is moving the lando file into the new drupal directory. Then I move that directory into my sites directory with an underscore appended since it's a duplicate name. Then I remove the original newsite directory and replace with the one I stashed at newsite_. At this point, everything is in place with my .lando.yml file inside newsite, and all the drupal files inside web (if that's what you chose as the web root).

  5. Rebuild

    lando rebuild

    Rebuild the site to make sure lando is wired up to the directories correctly. It will show green links if everything is in the right place.

Tags
Lando