- Windows 11
- WSL 2 (Windows Subsystem for Linux)
- Docker Desktop
-
Enable WSL: Open PowerShell as an administrator and run the following command to enable WSL:
wsl --install
-
Set WSL 2 as Default: Ensure WSL 2 is set as the default version:
wsl --set-default-version 2
-
Install a Linux Distribution: Install a Linux distribution from the Microsoft Store, such as Ubuntu.
-
Set Up Your Linux Distribution: Open the installed Linux distribution (e.g., Ubuntu) and complete the initial setup.
-
Download and Install Docker Desktop: Download Docker Desktop from Docker's official website and install it.
-
Enable WSL 2 Based Engine: During the installation, ensure the "Use the WSL 2 based engine" option is selected.
-
Configure WSL Integration: Open Docker Desktop and go to Settings -> Resources -> WSL Integration. Enable integration with your installed WSL 2 distributions (e.g., Ubuntu).
-
Open Ubuntu: Open your Linux distribution (e.g., Ubuntu) and navigate to your working directory.
-
Install Composer: If Composer is not already installed, run the following commands:
sudo apt update sudo apt install curl php-cli php-mbstring git unzip curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer
-
Create a New Laravel Project: Create a new Laravel project using Composer:
composer create-project laravel/laravel example-app cd example-app
-
Install Laravel Sail: Require Laravel Sail as a development dependency:
composer require laravel/sail --dev
-
Publish Sail's Docker Configuration: Publish Sail's Docker configuration:
php artisan sail:install
-
Start Docker Containers: Start the Docker containers:
./vendor/bin/sail up
-
Copy Environment File: Copy the
.env.example
file to.env
:cp .env.example .env
-
Generate Application Key: Generate a new application key:
./vendor/bin/sail artisan key:generate
-
Update Environment Variables: Update the
.env
file with the necessary database configuration if needed.
- Open Browser:
Open your browser and navigate to
http://localhost
. You should see the Laravel welcome page.
-
Stop Docker Containers:
./vendor/bin/sail down
-
Run Artisan Commands: To run other Artisan commands, prefix them with Sail:
./vendor/bin/sail artisan migrate
If you encounter any issues, ensure:
- Docker Desktop is running.
- WSL 2 is properly configured.
- The Linux distribution is properly set up.
By following these steps, you should have a fully functional Laravel Sail and Docker environment set up on your Windows 11 machine using WSL 2.