Categories
Web Development

Impressions: WSL2 for Laravel/LAMP Stack Development

A rundown of the recently publicly released WSL2 and how it fares as a solution for local LAMP Stack web development.

For those not aware, WSL is Windows feature called “Windows Subsystem for Linux.” Basically, it’s Linux running inside Windows.

The original version was released years ago, and was heavily integrated with Windows, offering a number of advantages over Virtual Machines (VM)- most notably a shared filesystem, so you didn’t have to keep your web files in a separate, far-removed location.

It was a good idea, and the official party line is that this option isn’t dead, but this subsequent release doesn’t inspire much confidence. Apparently trying to get Linux and Windows to play nicely together was challenging, buggy and slow enough to warrant a new direction.

WSL Is Dead! Long Live WSL!

The recently (publicly-)released WSL2 basically throws in the towel on the integrated approach, and is literally just another Linux VM. Separate user files, separate configuration files, just about separate everything.

So, why bother? There are plenty of other VMs out there, right?

Well, here’s the thing: it isn’t “just another VM.”

WSL2 is a highly Windows-optimized VM. And that’s not nothing; in the web development community, a Windows-based web developer invites comparisons to grown adults using training wheels.

Unlike most other consumer products, many web tools are obviously made with Windows as an afterthought.

So, a (free) solid VM is well-worth a look for us Windows peasants.

The Problem with VMs

Personally, I’ve been using Homestead/Virtualbox for a few years. It’s perfect for beginners, doing damn-near everything for you, and the fine folks at Laravel even hand-hold you through the start-up process with simple step-by-step instructions.

But after some time, you’ll come to realize there are some real problems.

The first, most obvious problem is that VMs are incredibly slow. On average, 5-10 seconds per page. More complex operations can take 20-60 seconds. And even “solutions” like NFS never reach the dizzying heights of “good.”

Startup times are considerable. Starting up these machines takes a solid 1-3 minutes, and goes up as you add more sites, databases, etc. And every time you need to adjust your configuration, you have to reload, and wait another 1-3 minutes.

The Windows Asterisks. If and when you run into technical issues, you may have to contend with the reality that Windows has its own problems, the solutions for which can be:

  • Hard to find, if they exist.
  • Complicated and vaguely defined.
  • May boil down to “sucks to be you.”

You can’t access your files via File Explorer. Cue the violins. In this line of work, using a terminal (command line) is pretty much standard, so I’m not expecting much sympathy, but I still prefer a nice GUI and a file tree.

WSL2: What It Is(n’t)

The transition from Homestead to WSL2 can be incredibly painful. Particularly if you’re stupid enough to skip prebuilt options like Homestead, Laradock or Valet, and just build your own LAMP server manually.

Yep, I’m that stupid. And that smart, since I now know how.

You don’t need to build your own server. I approached this with the idea that WSL2 was the alternative. And I didn’t want to stack bulky “alternatives” on top of it.

But the reality is, you’re just starting up a Linux machine. Not a server. There’s a massive amounts of “stuff” that needs to be plugged in and connected up for that. Those containers can save you all that trouble.

Which of those containers are best for WSL2, I can’t say. So, instead, let’s show you what “the hard way” can get you. And maybe it’ll inspire you to be “stupid” too.

Results & Impressions

Startup time is about five seconds. Four seconds for Ubuntu boot up. One second to run this .bashrc script, starting up essential services:

# Go to User Home Directory
cd /home/username

# Start Apache2
if service apache2 status > /dev/null
    then echo "Apache already running";
    else service apache2 start;
fi

# Start Mysql
if service mysql status > /dev/null
    then echo "MYSQL is already running";
    else service mysql start;
fi

# Git Preparation
if [ -z "$SSH_AUTH_SOCK" ] ; 
    then eval `ssh-agent -s`;
    else echo "SSH Agent already running."
fi

Page load times are beautiful. Every single page loads instantly. This alone validated all the frustration and headaches endured.

Composer has mixed performance. Running composer update can sometimes be slow. However, when pulling in cached packages, it flies like I’ve never seen before. It’s exhilarating to watch.

Battery life takes a noticeable hit. With everything running, I’ve noticed my laptop battery drains about 20-30% faster. Not horrific, but enough to lead me to a forum discussion in which it was suggested that Hyper-V has been accused of issue before.

Desktop Notifications are missing. If you use npm run watch (such as for Laravel Mix), this can be kind of a big deal. Hopefully, this will be patched in eventually.

(Silver lining, though: compilation does seem to be slightly faster.)

Virtualhost management is a bit of a pain. Enjoy editing Windows’ etc/hosts file? Well, now you get to manage Linux’s too!

(This can be done with a simple WSL restart, but either way, it’s a hassle and/or disruption. I long for virtualhost regex wildcards.)

Working from a different filesystem sucks. As already mentioned, Windows and the VM don’t share a filesystem. This has a few implications:

  • Assuming you want to keep your work files together, you’ll basically be working entirely from Linux from now on. And copying those files could be a very slow process.
  • While VS Code has a WSL extension, other editors, may be hindered. (I discovered that Atom can no longer search across multiple files.)
  • Reaching your files requires starting up WSL2. Obviously, hardly a big deal at 5 seconds, but if something goes wrong, there are questions about retrieval I am not currently prepared to answer.

Full control. For all the drawbacks, it’s important to bear in mind that this setup isn’t a black box you should be afraid to tinker with. If there’s a problem, you don’t have to wait for a patch. You can add any services or features you like.

And if you dare to try, you may become a better developer as a result.

Overall: A Decent Option

Looking down the list, it becomes clear WSL2 is far from perfect. I certainly wouldn’t recommend it to just anyone, especially at this early stage.

I certainly wouldn’t recommend it to beginners, since no matter what setup you go with, this route will require some technical knowledge.

But if you know what you’re doing, and want some real speed, and you either have or want some experience with Linux, this could be well worth your time and trouble.

By Britt Bodin

Professional computer-haver and learner of many things both noun and verb.