Drupal 8 Local Development


If you're on a Mac you can install Lando via Brew. However, it's recommended that you download the PKG file from the project's github Releases page.


There are a number of ways to get a Drupal development site up and running on your local machine but I found that the easiest and quickest method is as follows.

Project Setup

PROJECT_NAME, PROJECT_REPO, and MAJOR_VERSION are all dependent on your situation.

lando init --recipe drupal$MAJOR_VERSION --source remote --remote-url https://github.com/drupal-composer/drupal-project.git --remote-options="--branch $MAJOR_VERSION.x --depth 1" --webroot=$WEBROOT --name=$PROJECT_NAME
lando start
lando composer install
git remote set-url $PROJECT_REPO
mv .env.example .env
for e in development beta production ; do cp .env.example .env.$e ; done
chmod u+w $WEBROOT/sites/default

If you make a mistake such as running the lando init in the wrong directory make sure that stop and destroy the application. You must destroy the application because only stopping the application will reference the directory it was first created with.

Site Installation

There are two different ways to install the site the first is via the browser. In either case, you will need the database information to perform the install. To get the necessary information run lando info. Typically the database server will be database, the database, username, and password are all drupal8. If you are using Drupal 9, then replace drupal8 with drupal9.

lando info
[ { service: 'appserver',
     [ 'https://localhost:55008',
       'https://drupal.lndo.site/' ],
    type: 'php',
    healthy: true,
    via: 'apache',
    webroot: './web',
    config: { php: '/home/paulus/.lando/config/drupal8/php.ini' },
    version: '7.3',
    meUser: 'www-data',
    hasCerts: true,
    hostnames: [ 'appserver.drupalstarterapp.internal' ] },
  { service: 'database',
    urls: [],
    type: 'mysql',
    healthy: true,
    internal_connection: { host: 'database', port: '3306' },
    external_connection: { host: '', port: '55007' },
    healthcheck: 'bash -c "[ -f /bitnami/mysql/.mysql_initialized ]"',
    creds: { database: 'drupal8', password: 'drupal8', user: 'drupal8' },
    config: { database: '/home/paulus/.lando/config/drupal8/mysql.cnf' },
    version: '5.7',
    meUser: 'www-data',
    hasCerts: false,
    hostnames: [ 'database.drupalstarterapp.internal' ] } ]

The other option is to use the command line. When you have the database information you can run the lando rush command.


lando drush site-install standard --account-name=admin --account-pass=admin --site-name=drupal --db-url='mysql://drupal8:drupal8@database/drupal8'


Installing New Modules

There are two ways to install modules. The first is by going to the site (ex: https://drupal.lando.site/admin/reports/updates/install) and either uploading a module or providing a link to the module's archive.

The second and preferred way is using composer. To install the webform module, for example:

lando composer require drupal/webform
lando drupal module:install webform

In the event that you get a Could not delete /app/web/sites/default/default.services.yml message flip the user write bit on

After configuring the new module make sure that you export any changes so that they can be imported into the new site.

lando drush config:export
git add config/sync
git commit -m 'Added and configured Webform.'

Updating Modules

There is a lot more dependencies than you think when you create a Drupal project. The only dependencies that we want to update are the 'drupal/*' ones. Any additional dependencies will get updated accordingly.

>List all out of date Drupal dependencies:

lando composer outdated "drupal/*"
drupal/core                   8.9.13 9.1.5 Drupal is an open source content management platform powering millions of websites and applications.
drupal/core-composer-scaffold 8.9.13 9.1.5 A flexible Composer project scaffold builder.
drupal/core-dev               8.9.13 9.1.5 require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.
drupal/webform                5.25.0 6.0.2 Enables the creation of webforms and questionnaires.

To see a list of modules that have security updates:

lando drush pm:security

Update a specific module's minor number:

lando composer update drupal/webform --with-dependencies

To update a module to a new major version:

lando composer require drupal/webform:^6.0

Once you're updated the site run the following.

drush updatedb
drush cache:rebuild
drush config:export --diff

Updating Drupal Core

Updating Drupal itself is a bit more involved. Prior to updating core you should backup the entire site, this includes both the database and files.

lando drush sql:dump --gz
tar cf site.tar /path/to/site
composer update drupal/core --with-dependencies
lando drush updatedb
lando drush cache:rebuild