Skip to main content

As a web developer, you will most likely need to run local copies of a bunch of different web sites. Regularly switching between several sites daily.  Sometime Drupal, other Laravel and whatever frameworks that are in your toolkit.

 

Install Docker and Lando

Do you have Docker installed?  No, then go to the Docker Desktop page and download.

Now let's look in to Lando.  Have a look at the Lando releases on GitHub to download the latest package for your OS.

Run the installer. I had Docker already installed and open.  The installer picked this up and required Docker to be closed.  If you don't have it installed, you can also install Docker first.

I have the following versions currently installed:
Docker Desktop 3.6.0 (3.6.0.5487)
Lando (v3.6.2)

 

Add Drupal

Install Drupal in your target directory.  I prefer command line

composer create-project drupal-composer/drupal-project:9.x-dev ./ --no-interaction

As I was already in the directory, I set the install to the current directory using ./

 

Or add Laravel

Install Laravel in your target directory using command line:

composer create-project laravel/laravel ./

 

Initialize Lando

Simple command

lando init

During the process you'll be asked a bunch of questions:

? From where should we get your app's codebase? current working directory
options:
  acquia
❯ current working directory
  github
  lagoon
  pantheon
  platformsh
  remote git repo or archive

? What recipe do you want to use? drupal9
options:
  acquia
  backdrop
  drupal10
  drupal6
  drupal7
  drupal8
❯ drupal9
  joomla
  lagoon
  lamp
  laravel
  lemp
  mean
  pantheon
  platformsh
  symfony
  wordpress

? Where is your webroot relative to the init destination? .
? What do you want to call this app? alpha

All going well - Lando should start Docker, create two containers and leave you with instructions something like this:

   _  __                       _
  / |/ /__ _    __  _    _____( )_______
 /    / _ \ |/|/ / | |/|/ / -_)// __/ -_)
/_/|_/\___/__,__/  |__,__/\__/ /_/  \__/

  _________  ____  __ _______  _______  _      ______________ __  ___________  ______
 / ___/ __ \/ __ \/ //_/  _/ |/ / ___/ | | /| / /  _/_  __/ // / / __/  _/ _ \/ __/ /
/ /__/ /_/ / /_/ / ,< _/ //    / (_ /  | |/ |/ // /  / / / _  / / _/_/ // , _/ _//_/
\___/\____/\____/_/|_/___/_/|_/\___/   |__/|__/___/ /_/ /_//_/ /_/ /___/_/|_/___(_)

Your app has been initialized!

Go to the directory where your app was initialized and run lando start to get rolling.
Check the LOCATION printed below if you are unsure where to go.

Oh... and here are some vitals:

NAME      alpha
LOCATION  /Users/{your-name}/Sites/{directory}
RECIPE    drupal9
DOCS      https://docs.lando.dev/config/drupal9.html

During the installation, one of the files created was .lando.yml file.  Cross check that this file holds the following content

name: {name}
recipe: {recipe}
config:
  webroot: .

As I installed Drupal 9 in a directory named alpha my file was as follows:

name: alpha
recipe: drupal9
config:
  webroot: web

Note, the webroot isn't . but web instead.  This is due to the installation instruction earlier of adding Drupal as the codebase.

However, had I installed Laravel with a name of laravel9 the .lando.yml would look like:

name: laravel9
recipe: laravel
config:
  webroot: public

 

Start Docker

In the terminal window, type

lando start

The lando start command will inform you the url to access your local domain

   ___                      __        __        __     __        ______
  / _ )___  ___  __ _  ___ / /  ___ _/ /_____ _/ /__ _/ /_____ _/ / / /
 / _  / _ \/ _ \/  ' \(_-</ _ \/ _ `/  '_/ _ `/ / _ `/  '_/ _ `/_/_/_/
/____/\___/\___/_/_/_/___/_//_/\_,_/_/\_\\_,_/_/\_,_/_/\_\\_,_(_|_|_)

Your app has started up correctly.
Here are some vitals:

 NAME            {name}
 LOCATION        /Users/{your-name}/Sites/{directory}
 SERVICES        appserver, database
 APPSERVER URLS  https://localhost:62464
                 http://localhost:62465
                 http://{directory}.lndo.site:8000/
                 https://{directory}.lndo.site/

Any issues try quitting and restarting Docker.  To restart use the following command

killall Docker && open /Applications/Docker.app

 

Page not loading

The first time I went to the page, a directory listing of the site was showing.  So I needed to create a .httacess file with the following:

RewriteEngine On
RedirectMatch ^/$ /web/

Which will change the path from root to root/web directory.  All working well now.

 

Drupal install

As you work through the Drupal install pages, the database page you are going to need some details.  Access these details using

lando info

The result of this command will be something like

[ { service: 'appserver',
    urls:
     [ 'https://localhost:62464',
       'http://localhost:62465',
       'http://{name}.lndo.site:8000/',
       'https://{name}.lndo.site/' ],
    type: 'php',
    healthy: true,
    via: 'apache',
    webroot: '.',
    config: { php: '/Users/{your-name}/.lando/config/drupal9/php.ini' },
    version: '8.0',
    meUser: 'www-data',
    hasCerts: true,
    hostnames: [ 'appserver.{name}.internal' ] },
  { service: 'database',
    urls: [],
    type: 'mysql',
    healthy: true,
    internal_connection: { host: 'database', port: '3306' },
    external_connection: { host: '127.0.0.1', port: true },
    healthcheck: 'bash -c "[ -f /bitnami/mysql/.mysql_initialized ]"',
    creds: { database: 'drupal9', password: 'drupal9', user: 'drupal9' },
    config: { database: '/Users/{your-name}/.lando/config/drupal9/mysql.cnf' },
    version: '5.7',
    meUser: 'www-data',
    hasCerts: false,
    hostnames: [ 'database.{name}.internal' ] } ]

The database details are in the line

    healthcheck: 'bash -c "[ -f /bitnami/mysql/.mysql_initialized ]"',
    creds: { database: 'drupal9', password: 'drupal9', user: 'drupal9' },
    config: { database: '/Users/{your-name}/.lando/config/drupal9/mysql.cnf' },

Enter the following pulled from the creds line

Database name: drupal9
Database username: drupal9
Database password: drupal9

The advanced options details are accessed from

    type: 'mysql',
    healthy: true,
    internal_connection: { host: 'database', port: '3306' },
    external_connection: { host: '127.0.0.1', port: true },

Add the following pulled from the lines above

Host: database

Port number: 3306

 

Command line mysql

To access your mysql db via command line, using the data above enter the following

lando mysql -h {host} -u {username} -p {db_name}

Which becomes

lando mysql -h database -u drupal9 -p drupal9

If you don't want to manage your MySQL DB via command line, have a read through this article "Connecting your Lando DB with an external MySQL app (Sequel Ace) on an local environment".

 

Use a unique database name

Rather than using the default recipe database name - drupal9... how can you have this as a unique name instead?  In your .lando.yml file add the following:

services:
  phpmyadmin:
    type: phpmyadmin
    hosts:
      - database
  database:
    creds:
      user: {user}
      password: {password}
      database: {database}

Of course replace the words and braces.  For this change to kick in, you need to run

lando destroy && lando start

 

One on of my sites, a photo competition, I altered the fields as:

services:
  phpmyadmin:
    type: phpmyadmin
    hosts:
      - database
  database:
    portforward: 3309
    creds:
      user: photo
      password: photo
      database: photo

I've also added a static port by adding portfoward.

 

Warning an unhealthy database

Post running the command above, you find your response contains a warning

Waiting until database service is ready...
ERROR ==> database reported as unhealthy.
Starting photo_database_1 ... done
Killing photo_database_1 ... done
Scanning to determine which services are ready... Please standby...
Starting photo_database_1 ... done
Killing photo_database_1 ... done

  _      __              _           __
 | | /| / /__ ________  (_)__  ___ _/ /
 | |/ |/ / _ `/ __/ _ \/ / _ \/ _ `/_/
 |__/|__/\_,_/_/ /_//_/_/_//_/\_, (_)
                             /___/

Your app started up but we detected some things you may wish to investigate.
These only may be a problem.


 ■ The service "database" failed its healthcheck
   This may be ok but we recommend you run the command below to investigate:
   lando logs -s database


Here are some vitals:

 NAME            photo
 LOCATION        /Users/andrewfletcher/Sites/photo
 SERVICES        appserver, database
 APPSERVER URLS  https://localhost:56838
                 http://localhost:56839
                 http://photo.lndo.site:8000/
                 https://photo.lndo.site/

This is the response to the lando destroy && lando start commands.  However, for the database to pick up the change in credentials you will need to execute the command

lando rebuild

Now the response will be without issue.  Importantly, if you cross check by running an info command

lando info

The database section will be updated with the updated credentials.

service: 'database',
    urls: [],
    type: 'mysql',
    healthy: true,
    internal_connection: { host: 'database', port: '3306' },
    external_connection: { host: '127.0.0.1', port: '3309' },
    healthcheck: 'bash -c "[ -f /bitnami/mysql/.mysql_initialized ]"',
    creds: { database: 'photo', password: 'photo', user: 'photo' },
    config: {},
    version: '5.7',

 

Related articles