This tutorial will give you steps on how to create Laravel application using Laravel Sail on WSL 2 (Ubuntu 20 or 22) on Windows platform.
I assume you already have Docker Desktop installed on your Windows OS.
Next follow the steps to get Ubuntu 22.04 up running with WSL.
Install/configure WSL2 on Windows
Open windows PowerShell in Administrator mode and run the following command to enable Microsoft Windows Subsystem
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Enable Virtual Machine Platform feature:
You can enable it using Windows PowerShell or you can go into the setting to enable but I would l would prefer command as it is quicker
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Now restart your system to get Virtual Machine Platform working.
Download & Install Linux Kernel update package
You can use this link to download the official Linux Kernel package from Microsoft – Download Linux Kernel
Run downloaded exe file and follow the next step when you are ready
Set WSL2 as your default version
Open windows PowerShell and run following command to set WSL default version
wsl --set-default-version 2
Download Linux distribution from Microsoft Store
Open Microsoft Store and search for Ubuntu 20 or 22, I preferred using 22.04 her as it is latest and greatest.
Download Ubuntu 22.04.1 LTS:
Install by Clicking on Open button:
Setup Username and password
Configure Docker Desktop to use WSL Engine
Open docker desktop on your windows and click on Setting/Gear icon to open settings panel, visit Settings > General Pane and enable Use the WSL 2 based engine checkbox and Click Apply & Restart button
Docker WSL Integration
From docker desktop settings visit Settings > Resources Section, you should see your distros listed as showing below if not make sure that the WSL ubuntu distro is using WSL 2 version.
Check the listed Ubuntu of your choice and click Apply & restart button.
From here you should be able to login to your Ubuntu OS as well as use docker commands from Ubuntu, if not make sure Ubuntu & docker works together.
Create new Laravel Project
Now open up Windows Terminal, and login to your Ubuntu/Linux OS
curl -s https://laravel.build/example-app | bash
The above command will create a Laravel Application using latest LTS version of Laravel Framework.
Run Laravel Application using Sail
Now navigate into Laravel app (example-app) folder and run following command to run Laravel Sail
cd example-app ./vendor/bin/sail up
As soon you run the above command first time it will build the docker containers on your System. It will take little time and then you can access your application using localhost from Windows.
So basically, what is happening here is you running Ubuntu/Linux withing Windows and from Windows your accessing application which is running on Linux. 🙂