Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

angelorigo's avatar

How to setup a fresh laravel project using sail into windows with wsl 2

How to setup a fresh laravel project using sail into windows with wsl 2 and set up to enable to send email from windows using wsl2.

0 likes
2 replies
LaryAI's avatar

Certainly! Here’s a step-by-step guide to set up a fresh Laravel project using Sail on Windows with WSL 2, and configure it to send emails.


1. Install WSL 2 and Ubuntu

  • Open PowerShell as Administrator and run:
    wsl --install
    
  • Restart your computer if prompted.
  • Install Ubuntu from the Microsoft Store.

2. Install Docker Desktop for Windows

  • Download and install Docker Desktop: https://www.docker.com/products/docker-desktop/
  • In Docker Desktop settings, ensure "Use the WSL 2 based engine" is enabled.
  • Also, make sure your Ubuntu distribution is enabled under "Resources > WSL Integration".

3. Install Composer inside WSL 2

Open your Ubuntu terminal and run:

sudo apt update
sudo apt install curl unzip git php-cli php-mbstring php-xml php-zip php-curl
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

4. Create a New Laravel Project with Sail

Navigate to your projects directory (inside WSL, e.g., /home/yourname/code):

cd ~
mkdir code
cd code
composer create-project laravel/laravel example-app
cd example-app

5. Install Laravel Sail

php artisan sail:install

Choose your desired services (e.g., MySQL, Redis, MailHog, etc.).


6. Start Sail

First, ensure you are in your project directory:

./vendor/bin/sail up

Or, for detached mode:

./vendor/bin/sail up -d

7. Access Your Laravel App

Visit http://localhost in your browser. You should see the Laravel welcome page.


8. Configure Email Sending

Option A: Use MailHog (Recommended for Local Development)

  • When installing Sail, if you selected MailHog, it will be available.
  • In your .env file, set:
    MAIL_MAILER=smtp
    MAIL_HOST=mailhog
    MAIL_PORT=1025
    MAIL_USERNAME=null
    MAIL_PASSWORD=null
    MAIL_ENCRYPTION=null
    
  • Access MailHog UI at http://localhost:8025 to view sent emails.

Option B: Use a Real SMTP Provider (e.g., Gmail, Mailtrap, etc.)

  • Update your .env file with your SMTP provider's details:
    MAIL_MAILER=smtp
    MAIL_HOST=smtp.mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=your_username
    MAIL_PASSWORD=your_password
    MAIL_ENCRYPTION=null
    
  • Replace with your provider’s credentials.

9. Sending Email from Windows via WSL 2

Laravel running in Sail (Docker) inside WSL 2 can send emails using SMTP as long as it has network access. No extra configuration is needed for most SMTP providers or MailHog.


Summary

  • Use WSL 2 and Docker Desktop for a native-like development experience.
  • Use Sail to manage your Laravel environment.
  • For local email testing, use MailHog.
  • For real emails, use a real SMTP provider.

If you encounter any issues, ensure Docker Desktop is running and your WSL 2 Ubuntu instance has access to the project files.

Let me know if you need more details on any step!

1 like
Tray2's avatar

I know this is off topic, but I would suggest using Laravel Herd and dbngin instead, it will make you life so much easier.

Please or to participate in this conversation.