Working with Laravel

Lando offers a configurable recipe for spinning up Laravel apps. Let's go over some basic usage.

Prefer video tutorials?

Getting Started

Before you get started with this recipe we assume that you have:

  1. Installed Lando
  2. Read up on how to get a .lando.yml

If after reading #2 above you are still unclear how to get started then try this

# Go into a local folder with your site or app codebase
# You can get this via git clone or from an archive
cd /path/to/my/codebase

# Initialize a basic .lando.yml file for my recipe with sane defaults
lando init

# Commit the .lando.yml to your git repo (Optional but recommended)
git add -A
git commit -m "Adding Lando configuration file for easy and fun local development!"
git push

For more info on how lando init works check out this.

Starting Your Site

Once you've completed the above you should be able to start your Laravel site.

# Start up app
lando start

# Optionally run composer install if needed
lando composer install

If you visit any of the green-listed URLs that show up afterwards you should be welcomed with your application's index.php.

You may need to configure a local Laravel database connection. Run lando info and use the internal_connection information.

Importing Your Database

Once you've started up your Laravel site you will likely want to pull in a database before you can really start to dev all the dev. Importing a database can be done using our helpful lando db-import command.

# Go into my app
cd /path/to/my/app

# Grab your database dump
curl -fsSL -o database.sql.gz "https://url.to.my.db/database.sql.gz"

# Import the database
# NOTE: db-import can handle uncompressed, gzipped or zipped files
lando db-import database.sql.gz

You can learn more about the db-import command over here.

Tooling

Each Lando Laravel recipe will also ship with helpful dev utilities. This means you can use things like artisan, laravel, composer and php-cli via Lando and avoid mucking up your actual computer trying to manage php versions and tooling.

lando artisan                  Run artisan commands
lando composer                 Run composer commands
lando db-import <file>         Import <file> into database. File is relative to approot.
lando db-export                Export a database. Resulting file: {DB_NAME}.TIMESTAMP.gz
lando laravel                  Run laravel commands
lando mysql                    Drop into a MySQL shell
lando php                      Run php commands
# Do a basic laravel gut check with artisan
lando artisan env

# Run composer install
lando composer install

# List laravel commands
lando laravel list

# Drop into a mysql shell
lando mysql

# Check the app's php version
lando php -v

You can also run lando from inside your app directory for a complete list of commands.

Environment Config

By default, Laravel comes with a .env configuration file set to use homestead. You will want to modify the following .env key value pairs:

APP_URL=http://myproject.lndo.site
DB_HOST=database
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=laravel

If your app is already running, lando restart to ensure the changes are applied.

Configuration

Recipe

You can also manually configure the .lando.yml file to switch php versions, toggle between apache and nginx, activate xdebug or an optional caching backend, choose a database type and version, set a custom webroot locaton and use your own configuration files.

# Laravel recipe
name: laravel

# Start with the default laravel recipe
recipe: laravel

# Configure the Laravel recipe
config:

  # See: https://laravel.com/docs/5.6/installation#server-requirements

  # Optionally specify the php version to use.
  #
  # If ommitted this will default to the latest php version supported by Laravel.
  # Consult the `php` service to see what versions are available. Note that all
  # such versions may not be supported in Laravel 7 so YMMV.
  #
  # See: https://laravel.com/docs/5.6/installation#server-requirements
  #
  # NOTE: that this needs to be wrapped in quotes so that it is a string
  #
  php: '7.1'

  # Optionally specify whether you want to serve Laravel via Nginx or Apache
  #
  # If ommitted this will default to the latest apache
  #
  # See: https://laravel.com/docs/5.6/installation#web-server-configuration
  #
  via: nginx

  # Optionally specify the location of the webroot relative to your approot.
  # For Laravel this is usually 'public'
  #
  # If ommitted this will be your approot itself.
  #
  webroot: web/public

  # Optionally specify a primary database, this can be one of:
  #
  #   - `mysql`
  #   - `mariadb`
  #   - `postgres`
  #
  # If ommitted this will not install a db for you.
  #
  # see: https://laravel.com/docs/5.6/database#configuration
  #
  database: mariadb:10.1

  # Optionally specify a primary caching backend, this can be one of:
  #
  #   - `redis`
  #   - `memcached`
  #
  # If ommitted this will not install a db for you
  #
  # see: https://laravel.com/docs/5.6/cache#configuration
  cache: redis

  # Optionally activate xdebug
  #
  # If you are having trouble getting xdebug to work please see:
  # https://docs.devwithlando.io/services/php.html#using-xdebug
  xdebug: true

  # Optionally mix in your own config files
  #
  # If ommitted this will use "sane defaults" for your recipe type
  # conf:

    # For more information on setting these files check out the documentation
    # and examples
    #
    # Docs: https://docs.devwithlando.io/services/php.html
    # Examples: https://github.com/lando/lando/tree/master/examples
    #
    # server: config/laravel.conf
    # php: config/php.ini

    # For more information on setting these files check out the documentation
    # and examples for the relevant services:
    #
    # MySQL: https://docs.devwithlando.io/services/mysql.html
    # MariaDB: https://docs.devwithlando.io/services/mariadb.html
    # PostGres: https://docs.devwithlando.io/services/postgres.html
    #
    # Examples: https://github.com/lando/lando/tree/master/examples
    #
    # database: config/mysql

You will need to rebuild your app with lando rebuild to apply the changes to this file. You can check out the full code for this example over here.

Environment Variables

The below are in addition to the default variables that we inject into every container. These are accessible via php's getenv() function.

# The below is a specific example to ILLUSTRATE the KINDS of things provided by this variable
# The content of your variable may differ
LANDO_INFO={"appserver":{"type":"php","version":"7.1","hostnames":["appserver"],"via":"nginx","webroot":"web/public","config":{"server":"/Users/pirog/.lando/services/config/laravel/laravel.conf","conf":"/Users/pirog/.lando/services/config/laravel/php.ini"}},"nginx":{"type":"nginx","version":"1.13","hostnames":["nginx"],"webroot":"web/public","config":{"server":"/Users/pirog/.lando/services/config/laravel/laravel.conf","conf":"/Users/pirog/.lando/services/config/laravel/php.ini"}},"database":{"type":"mariadb","version":"10.1","hostnames":["database"],"creds":{"user":"laravel","password":"laravel","database":"laravel"},"internal_connection":{"host":"database","port":3306},"external_connection":{"host":"localhost","port":true},"config":{"confd":"/Users/pirog/.lando/services/config/laravel/mysql"}},"cache":{"type":"redis","version":"4.0","hostnames":["cache"],"internal_connection":{"host":"cache","port":6379},"external_connection":{"host":"localhost","port":true}}}

NOTE: These can vary based on the choices you make in your recipe config. NOTE: See this tutorial for more information on how to properly use $LANDO_INFO.

Automation

You can take advantage of Lando's events framework to automate common tasks. Here are some useful examples you can drop in your .lando.yml to make your Laravel app super slick.

events:

  # Composer install + custom script + artisan migrate
  post-start:
    - appserver: cd $LANDO_MOUNT && composer install
    - appserver: cd $LANDO_WEBROOT && php script.php
    - appserver: cd $LANDO_WEBROOT && artisan migrate

Advanced Service Usage

You can get more in-depth information about the services this recipe provides by running lando info.

Read More

Workflow Docs

Advanced Usage

results matching ""

    No results matching ""