Ashwin Mohan Ram

Manager, Client Services Projects

Assistant Front Office Manager

Information Technology Manager

Full-stack Laravel Vue.js Developer

Ashwin Mohan Ram

Manager, Client Services Projects

Assistant Front Office Manager

Information Technology Manager

Full-stack Laravel Vue.js Developer

Blog Post

Setting up a Laravel Dev machine on Windows 10 with WSL (Windows Subsystem for Linux) enabled

September 8, 2019 Web Development

I’m going to ramble on a bit about my thought process and the laptop I ended up buying, but if you want to jump straight to the setup information, just scroll down to Setting It Up.

I recently felt the need to upgrade my laptop to one with a larger screen, but kept holding off because I wanted to have a good development workflow. I’ve always been a Mac enthusiast and was considering saving up for a MacBook Pro but the 15″ model would have been a significant investment.

Once I learned about WSL on Windows 10 and having used the OS at work, I knew my next laptop would be a Windows 10 PC. To those of you who aren’t aware, WSL enables Linux to be installed on Windows 10 and it allows you to run the Linux distro of your choosing in parallel with Windows, i.e. without having to dual boot.

I did not require a state of the art computer for Laravel web development on Windows… the features I wanted were:

  1. 15.6″ screen
  2. 8GB RAM
  3. 256 SSD hard drive
  4. Intel i5 processor or an AMD equivalent
  5. UHD display

Lucky for me Comex 2019 was a week away so I held off and ended up buying an ASUS VivoBook 15 X512FJ that retails for SGD 999 for SGD 830 and got some additional freebies to boot. It wasn’t a Macbook Pro 15″ with a retina display and more impressive specs, but it also didn’t set me back SGD 3,499. The VivoBook came with a fingerprint sensor and it looked good to me as well so I didn’t hesitate to make the purchase.

ASUS VivoBook 15 X512FJ with fingerprint sensor

Setting It Up

The first step of course would be to activate WSL. I did this by running the following command through Windows PowerShell as an Administrator:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

The next step was to install the Linux distro through the Microsoft Store and I went with Ubutu 18.04 LTS as I was already familiar with it and never had any problems.

I then proceeded to install PHP 7.3, composer, mysql, redis, supervisor, node, npm and oh my zsh. There are a multitude of resources of how to do this online, so I’m sorry but I’m going to save myself the effort to add all the commands and provide you with the links instead.

The important thing though is I didn’t install Apache but having used Laravel Valet on my Mac as well as on Ubuntu (valet-linux) and found the entire workflow of adding projects and accessing them from the browser a no brainer.

The one thing I have to point out is valet-linux does not work with WSL. Please use valet-wsl instead but don’t forget to install the prerequisite Ubuntu packages.

Valet for WSL provides a way to quickly setup a development environment for Laravel using Valet in Windows Subsystem for Linux.

valeryan

By the way, I noticed I could not even do apt-get update after installation of valet-linux initially and had to add back the nameservers to fix this. Am not sure if this is even required if you install valet-wsl right away.

The last hurdle for me was automating the startup of the web stack upon launching the Ubuntu App after restarting Windows. Here is what I added to my ~/.zshrc file:

sudo valet start
sudo service supervisor start
sudo service redis-server start
sudo service mysql start
sudo supervisorctl start all

I used supervisor to launch Laravel Echo Server and Laravel Horizon upon boot. Please note that systemctl in not available in WSL based on what I read.

You will also need to add an entry into the Windows hosts file in order to access your web app on 127.0.0.1. Last but not least, in order to access your code in a text editor through Windows, you will need to store your code on the Windows file system by creating a sym link from WSL to Windows.

ln -s /mnt/c/Users/username/Documents/

You will then be able to use Sublime Text / Sublime Merge / etc through the Windows GUI but use the Ubuntu terminal for everything related to the server.

I hope this post helps someone to set up their development environment on Windows!

Write a comment