Getting Started with Laravel Development Using WSL on Windows
Set up a full Laravel development environment using WSL on Windows. This guide walks you through the installation process step by step.
Set up a full Laravel development environment using WSL on Windows. This guide walks you through the installation process step by step.

If you're using WSL (Windows Subsystem for Linux) and want to build Laravel applications, the first step is getting the Laravel installer set up properly. While installation is easy, many developers (including me!) hit a snag: after restarting the terminal, the laravel command stops working.

In this article, I’ll guide you through installing Laravel globally and fixing the "command not found" issue that happens after closing your terminal.


Step 1: Install Laravel via Composer

First, ensure you have Composer installed inside your WSL environment.

Then install the Laravel installer globally:

composer global require laravel/installer

This installs Laravel in your global Composer vendor/bin directory, which is not added to your PATH by default.


The Problem: laravel command not found after restarting terminal

After installation, you might be able to run:

laravel --version

But once you close and reopen the terminal, you'll get:

command not found: laravel

This happens because the directory where Composer installs global binaries isn't in your system's $PATH.


Step 2: Find Composer’s Global Bin Directory

Run this command to find the full path:

composer global config bin-dir --absolute

You'll likely see:

/home/your-username/.config/composer/vendor/bin

Copy that path.


Step 3: Add Laravel to Your $PATH

Now you need to permanently add that path to your shell configuration file so it loads every time you open the terminal.


For Bash users (~/.bashrc):

  1. Open the file:
nano ~/.bashrc
  1. Add this at the bottom (replace the path if yours is different):
export PATH="$HOME/.config/composer/vendor/bin:$PATH"
  1. Save with CTRL+O, hit ENTER, then exit with CTRL+X.
  2. Apply changes immediately:
source ~/.bashrc

For Zsh users (~/.zshrc):

  1. Open the file:
nano ~/.zshrc
  1. Add this at the bottom:
export PATH="$HOME/.config/composer/vendor/bin:$PATH"
  1. Save and exit:
    • CTRL+O, ENTER, CTRL+X
  2. Apply the changes:
source ~/.zshrc

Step 4: Confirm it Works After Restart

Close and reopen your terminal.

Then run:

laravel --version

You should now see the version without any error. 🎉


Tip: Check Your PATH

To verify the Laravel path is included:

echo $PATH

You should see something like:

/home/your-username/.config/composer/vendor/bin:...

You're Ready to Build with Laravel in WSL!

With Laravel now properly added to your PATH, you're ready to scaffold new projects:

laravel new my-app
cd my-app
code .
php artisan serve

Tip: Use Windows Databases with Laravel in WSL

You can create and manage your databases using tools installed on Windows, such as DBngin, and still connect to them from Laravel inside WSL.

Since WSL and Windows share the same network interface, you can connect to your DBngin database using 127.0.0.1 (localhost) and the port DBngin assigns (e.g., 3306 for MySQL).

Example .env for Laravel:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306 DB_DATABASE=your_db_name
DB_USERNAME=root
DB_PASSWORD=

Just make sure:

  • The DB server (MySQL/PostgreSQL) is running on Windows.
  • The port is accessible (no firewall issues).
  • You use 127.0.0.1 instead of localhost in .env, as sometimes localhost resolves differently in WSL.

This setup is great if you want to keep your development tools on Windows but code inside WSL!

Happy coding!

Achour Meguenni

Passionate tech enthusiast and a self-taught web developer.

2025 Achour, All rights reserved.

  • Contact
  • Achourphp@gmail.com