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.
Steps to get Laravel up on Lando
$ lando init --recipe laravel --webroot public --name My\ Project
$ lando start
This will create a
.lando.yml config file, and fire up a PHP and MySQL container based on the
laravel recipe. It correctly sets the
public/, 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
laravel recipe, have both
laravel CLI installed. We can clone a Laravel project using
git (must be installed on host) or start a new project from scratch.
$ lando laravel new my-project
$ lando composer create-project --prefer-dist laravel/laravel my-project
We initiated our Lando configuration above the
my-project directory, so let’s move
my-project/ 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
homestead as the database. We just need to edit the
.env file with the following. Note these values can be seen via
# @file .envAPP_URL=http://myproject.lndo.site
Then migrate the database schema.
$ lando artisan migrate
Some further notes and tips
Don’t cache local development. Basically, never run
php artisan config:cache.
You will want to take advantage of PHPUnit testing. You can make that tooling available in your
.lando.yml file, like so:
description: "Run PHP Unit tests: lando phpunit"
Laravel tutorials instruct us to configure
phpunit.xml to use a testing database configuration. However, with Lando (maybe Docker too) you must include the
force="true" attribute when doing so, like so:
<env name="DB_CONNECTION" value="sqlite" force="true" />
<env name="DB_DATABASE" value=":memory:" force="true" />
Now you should be able to follow any tutorials on Laravel. Keep in mind that you will use the
lando command to run commands within the container. Good luck!