DEV Community

Cover image for Laravel Sail on Windows
robencom
robencom

Posted on

Laravel Sail on Windows

I wanted to write my own detailed walkthrough on how to setup Laravel Sail on a Windows machine.

0- Install Windows Terminal from the Microsoft Store.

1- Check if Virtualization Technology is enabled in your BIOS:
UEFI BIOS (Advanced > CPU Configuration > SVM Mode or Virtualization Technology..

2- enable WSL with this command (via terminal or command prompt with Admin privileges):
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

3- enable VM with this command (via terminal or command prompt with Admin privileges):
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

4- Download the Linux kernel update package:
Download WSL2 Linux kernel update package for x64 machines

5- Set WSL2 as your default version (via terminal or command prompt with Admin privileges):
wsl --set-default-version 2

6- Instal Ubuntu 20.04.4 LTS (or whichever Ubuntu you desire) from the Microsoft Store and follow instructions

7- Run the command (via terminal or command prompt with Admin privileges) wsl --list --verbose to verify your installation.

8- Now, download and Install Docker Desktop

9- Open Docker Desktop:

  • in the General tab, click on the gear icon and make sure "Use wsl2 based engine" is checked.
  • in the Resources tab, check your ubuntu Integration and click Apply

10- Open Windows Terminal and cd ~ (to go to the home dir) then type this command to install a fresh Laravel project:
curl -s https://laravel.build/test-project | bash
Obviously, change "test-project" to whatever the name of the project that you desire.

11- To find the files of this project, just open your File Explorer and type: \\wsl$ then you can go to Ubuntu-20.04\home\YOUR_USERNAME\test-project

12- now in the terminal, cd to the new project (cd test-project) and type this command to start sail:
./vendor/bin/sail up
(this will take time for fresh installation)

13- to make an alias, in the terminal :
nano ~/.bashrc
then at the end of the file write:
alias sail='bash vendor/bin/sail'
then apply the change . ~/.bashrc

14- now we can stop it with sail down and turn it on with sail up, we can also pause it with CTRL+C, or as detached mode : sail up -d

15- If using PHPStorm: click File > Open > then type \wsl$\Ubuntu-20.04\ and look for your project

16- IMPORTANT: to shut down the VM, type in terminal:
wsl --shutdown
This will make sure that the VM is not taking memory when you are not using it!

17- As for the database, you can run sail artisan migrate to run the migrations.

18- To connect to the database through MySQL Workbench (or any other database IDE): connecting your SQL Management Software using localhost with the default username: sail and password: password.

DONEEEEEEEEEEEEEEEEEEEEEEEE!!!

So the daily routine after this would be:

        - open terminal
        - type wsl
        - cd ~ then go to the project dir
        - sail up -d
        - then open PHPStorm
Enter fullscreen mode Exit fullscreen mode

For more info, this was the reference I used: REF

Discussion (0)