How to start a new Laravel project with Laravel Sail without local installation of PHP
For some reason, since Laravel 12, official Laravel docs no longer provide guidance on how to set up Laravel project locally with Laravel Sail, without having PHP available on your machine - i.e. going right away for Docker, and skipping local installation of PHP altogether. It may seem like you have to use Laravel Installer, or third-party services like Laravel Herd, but it's not the case. Simple Laravel Sail setup still works just fine.
The only thing you need to do before is to make sure you have docker installed on your machine, and added sail alias, as described in Laravel Sail docs. This approach works both in WSL2 on Windows 11 and MacOS.
To set up the project, run the following command in your terminal:
APP_NAME=laravel-example
docker run \
--rm \
--interactive \
--tty \
--volume $(pwd):/app \
composer:latest \
bash -c " \
composer create-project \"laravel/laravel\" $APP_NAME \
&& \
cd $APP_NAME \
&& \
composer require laravel/sail --dev \
&& \
php artisan sail:install
"
There's no magic here. We first define the APP_NAME. Then, set up Laravel project in a directory called APP_NAME relative to the current directory using composer create-project (which was the approach mentioned in Laravel docs until Laravel 10). We then install Laravel Sail, and then run php artisan sail:install command. In the process, we use the official composer:latest docker imager image, which has PHP and composer installed, allowing us to set up the Laravel App.
And you’re done. You can run sail up -d, and then sail artisan --help to verify that things work as expected.
Sources: