Installing Drupal using Lando

When setting up a new Drupal site, you have a number of options for getting the code. You can download the archive, you could git clone the latest code, you could use composer. Since I've been using Lando for my dev environment, I will show how to download the code using Lando when you are initializing the container, either by using the archive or by getting the latest version from git.

Archive method

Using the archive method, we are instructing Lando to download the packaged version of Drupal, extract it, and set up our environment. We start off by making a directory for the new site, switch into that directory, then invoke lando init with some parameters to download the appropriate archive. We can either grab the latest release (at this time, that is 9.0.7) or, if we want a specific version, we can specify the archive for a given release.

# Create a directory for the new site
mkdir my_drupal_site

# Change into the site directory
cd my_drupal_site

# Initialize Lando to pull the latest version of Drupal
lando init --source remote --remote-url https://www.drupal.org/download-latest/tar.gz

# Note that the above will download the files into folder with the release name (e.g. drupal-9.0.7).
# To avoid this, strip the leading component from the archive via remote-options (note that the "="
# is required for this parameter)
lando init --source remote --remote-url https://www.drupal.org/download-latest/tar.gz --remote-options="--strip-components=1"

# If you want a specific version of Drupal (e.g. 8.9.7)
lando init --source remote --remote-url https://ftp.drupal.org/files/projects/drupal-8.9.7.tar.gz --remote-options="--strip-components=1"

GIT method

Downloading via git is similar to downloading the tar archive, other than we need to change the remote URL. Again, we can download either the latest master branch, or a specific branch if we want a given release. You can specify either https://git.drupal.org/project/drupal.git (which is the main repository) or https://github.com/drupal/drupal (which is a direct mirror) as the remote URL.

# Create a directory for the new site
mkdir my_drupal_site

# Change into the site directory
cd my_drupal_site

# Initialize Lando to pull the latest version of Drupal
lando init --source remote --remote-url https://git.drupal.org/project/drupal.git

# If you want a specific version of Drupal (e.g. 8.9.x)
lando init --source remote --remote-url https://git.drupal.org/project/drupal.git --remote-options="--branch 8.9.x --depth 1"

You will likely need to run composer install to finish up.

Note that if you set the branch to full version (e.g. 8.9.5) it will clone a detached head, which could lead to problems. You probably shouldn't be trying to install older versions of Drupal when starting a new site anyway, unless you just want to experiment.

Post-download

After downloading the code, you may need to run lando rebuild before you start the application. I'm not sure why this happens, but I'll get an error running lando drush until after I rebuild. Also, the URLs may show in red (meaning it couldn't set them up). Once the application is started, you can install Drupal using the UI or through Drush.

Updating

With either of the above methods, once you have downloaded Drupal, you can use lando composer update to update the code. Note that you may need to run lando composer install first. If you get errors about composer being unable to delete files, along with a timeout notice, and the update fails, you can increase or remove the timeout limit for composer. To do this for an individual container, edit the composer.json file and add the following:

{
  "config": {
    "process-timeout":0
  }
}

You will probably already have a config section to sort the packages, so add the process-timeout line within that. Note that it will probably take a very long time to run the update.