How to set up Tinkerwell on Windows and connect to WSL2 based Laravel projects.
I recently worked on a project with lots of interconnected relationships between various models and the best solution I could come up with in my attempt to debug and validate the data, was by either using Laravel Tinker and running the Eloquent queries there, or to dd() or Log::info out the result of a specific query.
Needless to say, I spent way too long trying to figure out, how to best go about extracting and manipulating the data I needed.
As a result, I decided to finally give Tinkerwell a try.
I downloaded the Windows version, installed it, and.... error upon error upon error upon...
Despite being an adept Google’er? it took me 4 hours to finally find a way through all the problems and get it connected to WSL2.
Seeing as there wasn’t any great guide on this, I thought I’d contribute with my setup path and hopefully, it’ll help you too.
Who’s this solution for?
As far as I could tell during my search, this seems to only be a problem for Windows 10 users, trying to connect to projects located in WSL2.
I personally use a Windows 10 machine with Docker installed (Windows side). I’m running a Ubuntu 20.04 VM through WSL2, where I have all my projects located in the /home/user/* path
I didn’t have PHP installed Windows side, only in WSL2.
Setup guide - Step by step.
- I had to bind my WSL2 network path to a Windows Drive in order to connect. I ran this command in Powershell. Obviously, change the Ubuntu-20.04 to match your WSL2 image.
net use * \\wsl$\Ubuntu-20.04 #Result: Drive Z: is now connected to \\wsl$\Ubuntu-20.04.
- Open Tinkerwell → Navigate to Settings → Connect the app to your PHP binaries path in Windows.
Meaning, downloading/Installing PHP on Windows, unless you already have it, and inserting the path to your php.exe or php-win.exe file.
I didn’t have PHP installed on Windows so I downloaded Xampp and downloaded PHP through that.
- If Tinkerwell doesn’t automatically respond to you attaching your PHP binaries with a “Detected version: ....”, then restart the application. I was stuck here for quite a while, wondering why it wouldn’t recognize my PHP binaries as it was meant to do. A quick restart of Tinkerwell was all that was needed.
- To connect to a WSL2 based project, click on: “Set Working Directory” (CTRL + O). Now, select your Ubuntu drive (In my case Z: ) and navigate to your desired project root folder → Select Folder.
- You should now be connected to your WSL2 based project! Check for your project name in the current Tab headline. Give it a go with a simple Eloquent Query and run your code!
Hint: I recommend running your code manually, as auto evaluating the code has a larger delay. Also, no point in auto evaluating something, that you’re still typing out.
Also: Forget about SSH access. That was my first attempt at connecting and I just couldn’t get it to work.
What if it still doesn’t work?
Throw away your Windows machine and buy a Macbook! God, I regret getting a Windows machine instead of a MacOS based :-( Jokes aside, I’ve linked a couple of the resources I used to find a solution.
Jake Harris has a potential solution requiring one to install X server. I couldn’t get that to work, but there’s a good chance you’re smarter than me, so who knows if that’s the missing key?