Installing Laravel 10 with Sail

This is a quick "writing it down" post because I typically hit this when bootstrapping a new Laravel application

TL;DR

1
2# Install Laravel via Docker
3docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/var/www/html" -w /var/www/html laravelsail/php82-composer composer create-project laravel/laravel example-app
4
5# Initialise Sail
6cd example-app
7docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/var/www/html" -w /var/www/html laravelsail/php82-composer php artisan sail:install --with=mysql,mailpit --no-interaction
8
9# Start app
10sail up
11

What does this do?

It is common when developing applications locally to use Docker. On my own local machine, I don't have PHP or composer installed at all, meaning I can't follow the exact steps outlined in the Laravel docs.

Instead, I use the docker run snippet above. The docker run stub is from the Sail documentation with thecreate-project and sail:install added.

The sail:install part is required to create the sail docker-compose config. Without it, you may received a sh: vendor/bin/sail: No such file or directory error

Feel free to customise the --with=mysql,mailpit section with the services you need.