The Untold Path to Laravel on Lando

UPDATE — Oct 7, 2018: Added a section with further notes on caching, configuration, and testing.

This tutorial will do one thing: help you get started with Laravel on Lando. You can read elsewhere about both Lando and Laravel, but if you’re here, you likely already know — Lando is a phenomenal tool for easing the pains of Docker containers for local development, and supports many popular languages, services, and options. This is an alternative to Homestead and Valet that works on Windows, Linux, and Mac.

The goal of this tutorial is to summarize in one place what you will gain from going through Lando’s documentation. Before you get started with this tutorial we assume that you have Installed Lando.

Steps to get Laravel up on Lando

$ lando init --recipe laravel --webroot public --name My\ Project
$ lando start

This will create a config file, and fire up a PHP and MySQL container based on the recipe. It correctly sets the to , and will serve your project at http://myproject.lndo.site.

At this point, we have a container we can work with, but no Laravel project. Our containers, based on the recipe, have both and CLI installed. We can clone a Laravel project using (must be installed on host) or start a new project from scratch.

$ lando laravel new my-project

or

$ lando composer create-project --prefer-dist laravel/laravel my-project

We initiated our Lando configuration above the directory, so let’s move into and restart.

$ mv .lando.yml my-project/
$ cd my-project
$ lando restart

The last thing we need to do is to configure our environment settings. Laravel’s default configuration file specifies as the database. We just need to edit the file with the following. Note these values can be seen via .

# @file .envAPP_URL=http://myproject.lndo.site
DB_HOST=database
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=laravel

Then migrate the database schema.

$ lando artisan migrate

Some further notes and tips

Caching

Don’t cache local development. Basically, never run .

PHPUnit

You will want to take advantage of PHPUnit testing. You can make that tooling available in your file, like so:

tooling:
phpunit:
service: appserver
description: "Run PHP Unit tests: lando phpunit"
cmd: /app/vendor/bin/phpunit

Laravel tutorials instruct us to configure to use a testing database configuration. However, with Lando (maybe Docker too) you must include the attribute when doing so, like so:

<env name="DB_CONNECTION" value="sqlite" force="true" />
<env name="DB_DATABASE" value=":memory:" force="true" />

Conclusion

Now you should be able to follow any tutorials on Laravel. Keep in mind that you will use the command to run commands within the container. Good luck!

Written by

code | faith | science | family

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store