Laravel is The PHP Framework For Web Artisans.
# Getting Started
Before you get started with this recipe, we assume that you have:
- Installed Lando and gotten familiar with its basics.
- Initialized a Landofile for your codebase for use with this recipe.
- Read about the various services, tooling, events and routing Lando offers.
However, because you are a developer and developers never ever RTFM (opens new window), you can also try out this recipe with a vanilla install of Laravel with the commands as follows:
# Initialize a laravel recipe lando init \ --source cwd \ --recipe laravel \ --webroot public \ --name my-first-laravel-app # Install laravel lando ssh -c "composer global require laravel/installer && laravel new app" # Start it up lando start # List information about this app. lando info
Here are the configuration options, set to the default values, for this recipe's Landofile. If you are unsure about where this goes or what this means, we highly recommend scanning the recipes documentation to get a good handle on how the magicks work.
recipe: laravel config: php: '7.3' composer_version: '2.0.7' via: apache:2.4 webroot: . database: mysql:5.7 cache: none xdebug: false config: database: SEE BELOW php: SEE BELOW server: SEE BELOW vhosts: SEE BELOW
Note that if the above config options are not enough, all Lando recipes can be further extended and overriden.
# Choosing a php version
You can set
php to any version that is available in our php service. However, you should consult the Laravel requirements (opens new window) to make sure that version is actually supported by Laravel itself.
The recipe config to set the Laravel recipe to use
7.1 is shown below:
recipe: laravel config: php: '7.1'
# Choosing a composer version
You can set
composer_version to any version that is available in our php service.
recipe: backdrop config: composer_version: '1.10.1'
# Choosing a web server
By default, this recipe will be served by the default version of our apache service but you can also switch this to use
nginx. We highly recommend you check out both the apache and nginx services before you change the default
# With Apache (default)
recipe: laravel config: via: apache
# With nginx
recipe: laravel config: via: nginx
# Choosing a database backend
By default, this recipe will use the default version of our mysql service as the database backend but you can also switch this to use
mariadb or 'postgres' instead. Note that you can also specify a version as long as it is a version available for use with lando for either
Also note that like the configuration of the
php version, you should consult the Laravel requirements (opens new window) to make sure the
version you select is actually supported by Laravel itself.
# Using MySQL (default)
recipe: laravel config: database: mysql
# Using MariaDB
recipe: laravel config: database: mariadb
# Using Postgres
recipe: laravel config: database: postgres
# Using a custom version
recipe: laravel config: database: postgres:9.6
# Choosing a caching backend
By default, this recipe will not spin up a caching backend.
However, you can specify one using the
cache recipe config and setting it to use either our use
memcached service. Note that you can optionally/additionally specify a particular version for either as long as it is a version documented as available for use with lando for either service.
# Using redis (recommended)
recipe: laravel config: cache: redis
# Using Memcached
recipe: laravel config: cache: memcached
# Using a custom version
recipe: laravel config: cache: redis:2.8
# Using xdebug
recipe: laravel config: xdebug: true|false
However, for more information we recommend you consult the php service documentation.
# Using custom config files
You may need to override our default Laravel config (opens new window) with your own.
If you do this, you must use files that exist inside your application and express them relative to your project root as shown below:
Note that the default files may change based on how you set both
via. Also note that the
server config will be either for
nginx depending on how you set
via. We highly recommend you check out both the apache and nginx if you plan to use a custom
# A hypothetical project
Note that you can put your configuration files anywhere inside your application directory. We use a
config directory but you can call it whatever you want such as
.lando in the example below:
./ |-- config |-- default.conf |-- my-custom.cnf |-- php.ini |-- server.conf |-- index.php |-- .lando.yml
# Landofile using custom laravel config
recipe: laravel config: config: database: config/my-custom.cnf php: config/php.ini server: config/server.conf vhosts: config/default.conf
# Environment File
By default, Laravel comes with a
.env configuration file set to use
homestead. You will want to modify the following
.env key so that it makes sense for use with Lando.
What that file would look like if you installed laravel as above is shown below:
Note that your file might be slightly different depending on your configuration.
APP_NAME=Laravel APP_ENV=local APP_DEBUG=true APP_URL=http://my-first-laravel-app.lndo.site LOG_CHANNEL=stack # If you set `database: mysql|mariadb` in this recipes config DB_CONNECTION=mysql DB_HOST=database DB_PORT=3306 DB_DATABASE=laravel DB_USERNAME=laravel DB_PASSWORD=laravel # If you set `database: postgres` in this recipes config # DB_CONNECTION=pgsql # DB_HOST=database # DB_PORT=5432 # DB_DATABASE=laravel # DB_USERNAME=postgres # DB_PASSWORD=null BROADCAST_DRIVER=log CACHE_DRIVER=file QUEUE_CONNECTION=sync SESSION_DRIVER=file SESSION_LIFETIME=120 # If you have `cache: redis` in this recipes config # REDIS_HOST=cache # REDIS_PASSWORD=null # REDIS_PORT=6379 # If you added a mailhog service to this recipe # MAIL_DRIVER=smtp # MAIL_HOST=sendmailhog # MAIL_PORT=1025 # MAIL_USERNAME=null # MAIL_PASSWORD=null # MAIL_ENCRYPTION=null
# Connecting to your database and/or cache
Lando will automatically set up a database with a user and password and also set an environment variable called
LANDO INFO that contains useful information about how your application can access other Lando services.
The default database connection information for a Laravel site is shown below:
Note that the
host is not
database: laravel username: laravel password: laravel host: database # for mysql port: 3306 # for postgres # port: 5432
If you've also specified a caching backend, the default connection settings are shown below:
host: cache # Redis port: 6379 # Memcache port: 11211
You can also get the above information, and more, by using the
lando info command.
# Importing Your Database
Once you've started up your Laravel site, you will need to pull in your database and files before you can really start to dev all the dev. Pulling your files is as easy as downloading an archive and extracting it to the correct location. Importing a database can be done using our helpful
lando db-import command.
# 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 # Due to restrictions in how Docker handles file sharing your database # dump MUST exist somewhere inside of your app directory. lando db-import database.sql.gz
You can learn more about the
db-import command over here.
By default, each Lando Laravel recipe will also ship with helpful dev utilities.
This means you can use things like
php via Lando and avoid mucking up your actual computer trying to manage
php versions and tooling.
lando artisan Runs artisan commands lando composer Runs composer commands lando db-export [file] Exports database from a service into a file lando db-import <file> Imports a dump file into database service lando laravel Runs laravel commands lando mysql Drops into a MySQL shell on a database service lando php Runs php commands
# Usage examples
# 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. This is always advisable as your list of commands may not be 100% the same as above. For example, if you set
database: postgres you will get
lando psql instead of