ashwinmram
11 months ago
5560
9
Tips

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

Posted 11 months ago by ashwinmram

The first step of course would be to activate ASL. 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 Im sorry but Im going to save myself the effort to add all the commands and provide you with the links instead.

The important thing though is I didnt 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 dont 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/Code/projectname

I hope this post helps someone to set up their development environment on Windows! Please read the entire blog I wrote on this which has more external links as well as some information about the laptop I am using.

https://ashwinmram.com/2019/09/08/setting-up-a-laravel-dev-machine-on-windows-10-with-wsl-windows-subsystem-for-linux-enabled/

Please sign in or create an account to participate in this conversation.