Set Up WSL2 for Web Development on Windows: PHP, Laravel, Node and VS Code

By Eddie Power Oct 20, 2026 in Web Development 7 min read
Windows WSL Laravel PHP Node.js VS Code

I build Laravel and PHP sites for a living, and I switch between Linux, macOS and Windows every day. For years Windows was the awkward one for PHP work. WSL2 changed that. It runs a real Linux kernel alongside Windows, so you get the same tools your production server uses, while keeping your Windows apps, browser and VS Code.

This guide is the setup I'd give anyone starting fresh: install WSL2 and Ubuntu, add PHP, Composer, Laravel and Node, connect VS Code, and avoid the one mistake that makes WSL feel slow. There's a troubleshooting section at the end for the errors I see most often.

Prerequisites

  • Windows 11, or Windows 10 version 2004 or later (build 19041+). That's Microsoft's stated minimum for the one-command install. Check with Win + R, then winver.
  • An administrator account.
  • Hardware virtualization enabled in your BIOS/UEFI (often labelled Intel VT-x, AMD-V or SVM). Most modern PCs ship with it on.
  • Visual Studio Code installed on Windows (not inside Linux).
  • A few GB of free disk space.

Step 1: Install WSL2 and Ubuntu

Right-click the Start button, choose Terminal (Admin) or Windows PowerShell (Admin), and run:

wsl --install

That enables the required Windows features and installs Ubuntu as the default distribution. Restart when asked. Microsoft's Install WSL guide is the official reference.

After the restart, Ubuntu opens and asks you to create a Linux username and password. They're separate from your Windows login. You'll need that password for sudo.

Check everything is on WSL 2:

wsl --list --verbose
wsl --status
wsl --update

The VERSION column should say 2. If you'd rather pick a specific Ubuntu release, list what's available and install by name:

wsl --list --online
wsl --install -d Ubuntu-24.04

Step 2: Update Ubuntu and check systemd

Open Ubuntu from the Start menu or Windows Terminal and bring it up to date:

sudo apt update && sudo apt upgrade -y

Many services (MySQL, Redis, etc.) expect systemd. Check whether it's running:

ps -p 1 -o comm=

If that prints systemd, you're set. If not, and /etc/wsl.conf doesn't already have a [boot] section, enable it:

printf '[boot]\nsystemd=true\n' | sudo tee -a /etc/wsl.conf

Then, from PowerShell, run wsl --shutdown and reopen Ubuntu. The WSL configuration docs cover wsl.conf in full.

Step 3: Keep your code in the Linux file system

This is the most important tip in the whole guide. Your Windows drives are mounted inside Linux at /mnt/c, and it's tempting to work there. Don't. Microsoft's file systems guidance is clear: for the fastest performance, store your files in the WSL file system when you're working with Linux tools.

In practice, composer install, npm install and file watchers on /mnt/c can be painfully slow, and hot reload may not notice changes at all. Make a projects folder in your Linux home instead:

mkdir -p ~/code && cd ~/code

You can still reach those files from Windows. Run explorer.exe . from any Linux folder to open it in File Explorer, or browse to \\wsl.localhost\Ubuntu\home\<your-user>\code.

Step 4: Install PHP, Composer and the Laravel installer

Laravel's installation docs recommend php.new, which installs PHP, Composer and the Laravel installer in one go:

/bin/bash -c "$(curl -fsSL https://php.new/install/linux/8.5)"

Check the Laravel docs for the current version number in that URL before you run it. Close and reopen the terminal afterwards.

Prefer Ubuntu's own packages? They're a good alternative, and they update with apt like everything else:

sudo apt install -y php-cli php-mbstring php-xml php-curl php-zip php-sqlite3 php-mysql php-intl php-bcmath unzip git composer
php -v
composer -V

Check that php -v meets the minimum for the Laravel version you're using (Laravel 13 needs PHP 8.3 or later; Ubuntu 24.04's default PHP is 8.3). Then install the Laravel installer and put Composer's global bin folder on your PATH:

composer global require laravel/installer
echo 'export PATH="$(composer global config bin-dir --absolute 2>/dev/null):$PATH"' >> ~/.bashrc
source ~/.bashrc
laravel --version

Step 5: Install Node.js with nvm

Ubuntu's packaged Node is often older than the current LTS release. I use nvm, so I can switch versions per project. Check the nvm README for the latest version number in this URL (v0.40.8 at the time of writing):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.8/install.sh | bash
source ~/.bashrc
nvm install --lts
node -v
npm -v

Step 6: Create and run a Laravel app

cd ~/code
laravel new example-app
cd example-app
npm install && npm run build
composer run dev

The installer asks a few questions about your starter kit, testing framework and database. SQLite is the simplest choice to start with. composer run dev starts the Laravel server, queue worker and Vite together. Open http://localhost:8000 in your normal Windows browser. WSL forwards localhost to Windows automatically.

Step 7: Connect VS Code to WSL

  1. In VS Code on Windows, install the WSL extension from Microsoft (ID ms-vscode-remote.remote-wsl).
  2. In your Ubuntu terminal, go to your project and run code ..
  3. The first time, VS Code installs a small server inside WSL. Then a window opens with WSL: Ubuntu in the bottom-left corner.

Now the terminal, Git, PHP and Node inside VS Code all run in Linux, while the editor runs on Windows. Extensions you install while connected (PHP Intelephense, the Laravel extension, ESLint) are installed on the WSL side. See Microsoft's VS Code with WSL tutorial and the VS Code WSL docs.

Set your Git identity once inside Ubuntu:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Step 8: Optional tuning with .wslconfig

WSL2 runs as a lightweight VM, and by default it can use a large share of your RAM. To cap it, create C:\Users\<you>\.wslconfig in Notepad:

[wsl2]
memory=8GB
processors=4

On Windows 11 22H2 and later you can also add networkingMode=mirrored under [wsl2], which can help with VPNs and IPv6. Apply changes from PowerShell:

wsl --shutdown

Microsoft notes that settings only apply once the VM has fully stopped. Its docs call this the "8 second rule", so wait a few seconds before reopening Ubuntu.

Troubleshooting

  • Error 0x80370102 ("the virtual machine could not be started"): virtualization is off in the BIOS/UEFI, or the Virtual Machine Platform Windows feature isn't enabled. Turn both on and restart.
  • wsl --install just prints the help text: WSL is already installed. Use wsl --list --online and wsl --install -d <Distro>.
  • Install stuck at 0.0%: try wsl --install --web-download -d Ubuntu, which Microsoft suggests for this.
  • Everything is slow, or Vite hot reload doesn't fire: your project is under /mnt/c. Move it to ~/code (Step 3).
  • laravel: command not found: Composer's global bin folder isn't on your PATH. Re-run the echo 'export PATH=...' line from Step 4 and open a new terminal.
  • could not find driver: you're missing a PHP extension. Install the one for your database, such as php-mysql or php-sqlite3.
  • localhost:8000 doesn't load in Windows: make sure the server is still running in the terminal, try http://127.0.0.1:8000, and if you're on a VPN, try networkingMode=mirrored from Step 8.
  • Settings changes don't apply: run wsl --shutdown, wait, then reopen.
  • Anything else: Microsoft's WSL troubleshooting page lists the common error codes.

Wrapping up

Once it's set up, WSL2 makes Windows a genuinely good PHP and Laravel machine. Your code runs on Linux like it will in production, and you keep your Windows tools. The two things that matter most are keeping projects inside the Linux file system and opening them with code .. Get those right and most of the "WSL is slow" complaints go away.

Share this article

E
Eddie Power admin

Eddie Power is a full-stack web developer based in Frankston, Victoria, with more than a decade of experience building websites, Laravel and PHP applications and iOS apps. He uses Linux, Windows and macOS every day, self-hosts this blog on a Synology NAS and writes practical guides for all three.

Comments (0)

No comments yet. Be the first to leave one!

Leave a Comment

Comments are moderated and will appear after approval.