Getting Started With Laravel and WSL2
Simplifying Laravel Development on Windows with WSL2 and Laravel Sail
March 11, 2023
1k ViewsWhy WSL2
WSL2 is the preferred environment on Windows to develop a Laravel application. Laravel offers a first-party package that simplifies working with your application in a dockerized environment.
Laravel Sail is a lightweight command-line interface for interacting with Laravel's default Docker development environment. Sail provides a great starting point for building a Laravel application using PHP, MySQL, and Redis without requiring prior Docker experience.
Out of the box, Laravel Sail includes services such as:
- PHP
- MySql
- Redis
- MailPit
- Meilisearch
- Selenium
You get all of this for free just by using Laravel Sail in WSL2.
But First
To get started you need to have the following installed:
- WSL2 installed and enabled
- Access to your WSL2 from a command line application
- Docker Desktop that is configured to use the WSL2 backend
Let's Download
Launch your Windows Terminal and begin a terminal session in WSL2. To create a laravel application in the command line use the following command:
curl -s https://laravel.build/my-app | bash
This does two things:
- A directory call
my-app
is created - Files are downloaded to the new
my-app
directory
Naturally you can replace my-app
with whatever name you like.
Let's Get Our Application Running
In your command line navigate to your freshly created folder. In this case it would look like this:
cd my-app
./vendor/bin/sail up
If this is the first time you run sail up
, it will probably take a while to download the docker images.
Once it is done, you can view your new app in your web browser at http://localhost.
Note: if you have any problems relating permission errors you, check out this article: