For a guy that used XAMMP for most of his development career,I must say that Lando improved a lot of my local development experience. Don't get me wrong, XAMMP pretty much works most of the time, but it is not the best choice if you want a reproducible development environment or deal with different codebases. Lando not only tackles these needs by handling the creation and maintenance of Docker containers but also provides support for tasks like importing/exporting databases or adding Xdebug.
The following lines do not mean to be an exhaustive guide about Drupal development with Lando, but they should get you through the basics.
Download Lando for you operating system and install it. I have it running on a Windows 10 and on an Ubuntu machine. The Linux instalation went pretty straight forward. On Windows, after the installation you must run Docker Desktop and, in Settings, navigate to the Shared tab and give permissions to your drives.
At the time of instalation, drive sharing didn't work in Windows Azure AD's accounts. You will have to create a local account on your PC to overcome this issue. For further information check #132, #364 or this solution.
For new projects you can simply go to the directory where you have your Drupal site, fire a new terminal and run lando init
.
Choose a recipe and fill the project options and details, this procedure will create a .lando.yml file that will have all the information for Docker to build all development assets (images, containers, networks, etc).
After this procedure, you will see the following:
NAME < site name />
LOCATION < path on your computer />
SERVICES appserver, database, < your services />
APPSERVER URLS https://localhost:32976
http://localhost:32977
http://< site name />.lndo.site
https://< site name />.lndo.site
You then can navigate to one of APPSERVER URLs and start developing. To see more details about the project (databases, services, etc.) run lando info
.
The following structure will add basic Drupal 8 recipe, drush aliases, Xdebug and configure the port for external access to the database.
name: < project name />
recipe: drupal8
config:
webroot: ./< your drupal root directory />
services:
appserver:
xdebug: true // add Xdebug
build:
- /bin/sh -c "mkdir -p ~/.drush/sites" // create drush/sites directory
- /bin/sh -c "ln -sf /app/build/drush/sites/self.site.yml ~/.drush/sites/self.site.yml" // copy your drush alias file via symbolic link
database:
portforward: 3307 // port for external access to the database from administration tools like phpMyAdmin or MySQL Workbench p.e
For Drupal multisite installations, you have to add extra database services and proxies for each site. The following recipe is for Drupal 7, but also works for the Drupal 8 recipe.
name: < project name />
recipe: drupal7
config:
webroot: ./< your drupal root directory />
php: 5.6
proxy:
appserver:
- < site 1 />.lndo.site
- < site 2 />.lndo.site
services:
appserver:
build:
- /bin/sh -c "mkdir -p ~/.drush/site-aliases"
- /bin/sh -c "ln -sf /app/lando/drush/site-aliases/< project name />.aliases.drushrc.php ~/.drush/site-aliases/< project name />.aliases.drushrc.php"
< site 1 />:
type: mysql:5.7
portforward: 3307
< site 2 />:
type: mysql:5.7
portforward: 3308
For a quick start just use this Drush command (got it from here):
lando drush site-install standard --account-name=< admin username /> --account-pass=< admin password /> --db-url='mysql://drupal8:drupal8@database/drupal8' --site-name=< site name />
If you want to install Drupal the usual way, just add the credentials to settings.php / local.settings.php, for Drupal 8 you have:
$databases['default']['default'] = array (
'database' => 'drupal8',
'username' => 'drupal8',
'password' => 'drupal8',
'host' => 'database',
...
);
Start development:
lando start
View configurations:
lando info
Add new services, fix errors while keeping all your data:
lando rebuild
Import database:
lando db-import < database file />
Import database to a different service/host:
lando db-import < path_to/database_file /> --host <host name />
Export database::
lando db-export < database file />
Export database from a different service/host:
lando db-export --host <host name /> < path_to/database_file />
SSH into the container:
lando ssh
Access container logs:
lando logs -s SOME_SERVICE
If you encounter an error during runtime, check out the runtime logs at
C:\Users\{ME}\.lando\logs
. There should be an error.log and a more robust lando.log.
Stop development:
lando stop | lando poweroff
Run drush commands:
lando drush < commands />
Run composer commands:
lando composer < commands />
One of the best ways to troubleshoot an issue is to use Docker commands directly or use the lando ssh or lando info --deep command.
# List all my containers
docker ps --all
# List all lando containers
docker ps --filter label=io.lando.container=TRUE --all
# List all containers for a particular app
docker ps --all | grep appname
# Inspect a container
docker inspect appname_service_1
# Check out the logs for a container
docker logs appname_service_1
# Attach to a container (this is like SSHing)
docker exec -i -t appname_service_1 bash