valeryan / valet-wsl

A fork of Laravel Valet for Ubuntu modified to work in WSL.
MIT License
147 stars 23 forks source link

Discussion of Known issues with Valet on WSL2 #7

Open tnaffh opened 5 years ago

tnaffh commented 5 years ago

Does this support WSL 2 latest release? if it does, would it work the same way?

valeryan commented 5 years ago

I don't have WSL 2 setup anywhere to test with currently. Confirmation from users that have WSL 2 installed would be helpful.

victorlap commented 5 years ago

I have WSL 2 installed and everything seems to work perfectly. Apart maybe from the fact that I can't get valet secure to work. Although I doubt this has something to do with WSL 2.

maarten-v commented 5 years ago

Nice! What error did you get? And you had to install the Windows Insider to get WSL2 right?

victorlap commented 5 years ago

Yes, you have to be an insider to get the Windows 10 20H1 build (which includes WSL 2)

I don't get an error, but Firefox complains that the certificate is not secure (although this might have to do with the fact that I'm using Firefox, I have not tested this in another browser atm).

valeryan commented 5 years ago

Yeah, I should add a note somewhere about Firefox. Firefox uses it's own trusted certificate store. The script to install the wsl CA cert only adds it to windows cert store which only covers chrome and ie. You can add the cert in C/tools/wsl/certs to Firefox manually and it will then work for valet secure.

victorlap commented 5 years ago

Whoops. Turns out I was not using WSL2, sorry guys! I thought that by running in the Fast track I would automatically have the latest WSL as well, but I needed to activate it manually.

After doing so I discovered that WSL2 and Acrylic both want to use port 53 and therefore cannot be ran together atm. See also https://github.com/microsoft/WSL/issues/4364 for more information.

Another things that you would need to change is the Acrylic settings, as localhost is not forwarded to the linux vm anymore (although they are working on supporting this https://docs.microsoft.com/en-us/windows/wsl/wsl2-ux-changes#accessing-network-applications).

valeryan commented 5 years ago

When wsl 2 comes out I may be able to use dnsmasq as normal. It may also render this project unneeded as well. The wsl for Linux may be all that is needed when it is released.

martinwolf commented 5 years ago

I hope it's okay to chime in. Has Microsoft said anything about a release date of WSL2?

valeryan commented 5 years ago

@martinwolf I don't think it has been announced when WSL 2 will be publicly available. It's currently available as part of the Windows Insider program if you sign up for the fast ring.

When WSL2 does official release I will test a few things and then may deprecate this project. There are 3 main changes that this package provides that make it work with WSL

  1. Changes to configuration to make WSL use ip:port for accessing fpm instead of socks
  2. Changes to how startup and services are handled to be compatible with WSLs lightweight handling of run time services.
  3. Disabling the DNSMasq stuff that is incompatible with WSL

WSL 2 has a full Linux kernel and a more robust service handling along with possible support for socks and better networking. It may be able to run everything in the valet Linux package natively.

The reason that Acrylic and WSL2 conflict is that dnsmasq in WSL2 grabs port 53 and in theory should be able to work as a DNS proxy for windows like Acrylic is doing, thus removing any need for Acrylic as well.

All that would be pretty nice to have but I don't feel like setting up an environment to test WSL2 right now because I would have to move to the Insider fast ring on a windows pc somewhere. I will wait for it to release and then figure out if this project is still needed.

valeryan commented 5 years ago

As far as I can tell WSL2 does not cause any issue with valet-wsl. I still can't get dnsmasq to work for windows though so that is disappointing.

valeryan commented 4 years ago

I changed the title of this to make it a de facto place to discuss any issues that are found with WSL2.

valeryan commented 4 years ago

If https://github.com/microsoft/WSL/issues/4592 gets resolved I will hopefully be able to switch this over to using dnsmasq at some point. Currently, the only issue I know of with running valet-wsl under WSL2 is the conflict between Acrylic and dnsmasq both trying to bind port 53.

tnaffh commented 4 years ago

I changed the title of this to make it a de facto place to discuss any issues that are found with WSL2.

Great

irakan commented 4 years ago

WSL 2 has a full Linux kernel and a more robust service handling along with possible support for socks and better networking. It may be able to run everything in the valet Linux package natively. I tried to install valet Linux package natively using wsl2, but it seems it doesnt work.. and I dont know why!? https://stackoverflow.com/questions/60518957/valet-status-is-showing-is-stopped

I reinstalled using your fork, and now its working great.

valeryan commented 4 years ago

valet-wsl has a patch that helps it better determine the services state and valet-linux is probably not going to work out of the box. However, if the changes become minor tweaks instead of large changes then they can hopefully be upstreamed into valet-linux.

I am not running fast ring on my windows system so I don't have ways of testing WSL 2 currently. When it is released I will evaluate how and if this fork is still needed.

Thanks for the info.

thomasaull commented 4 years ago

@irakan could you outline the steps you have taken to mak valet-wsl work with WSL2? I can't get it running

valeryan commented 4 years ago

@thomasaull the only thing that is known not to work right now is the port conflict between dnsmasq and acrylic proxy in windows. You should be able to follow the install guide. https://github.com/valeryan/valet-wsl/wiki/Installation-Guide

nickescobedo commented 4 years ago

I followed the guide but still haven't been able to get it working with WSL2.

Domains aren't resolving and I can't figure out how to get it working. I've disabled dnsmasq.

The domains don't appear to route through Acrylic at all.

valeryan commented 4 years ago

Does your domain route to 127.0.0.1 when you ping it from windows cmd line? If acrylic is running and configured correctly your domain will point to your internal up.

I don't official support WSL2 at the moment because it is very much in flux and has some network issues. Some of which may be fixed on the fast ring. See https://github.com/microsoft/WSL/issues/4769 and https://github.com/microsoft/WSL/issues/4636 as examples.

thomasaull commented 4 years ago

I got it running with a workaround. Basically installing Acrylic made the WSL2 don't start anymore (don't know why, didn't investigate). For routing the hosts from windows to WSL2 I'm using https://github.com/shayne/go-wsl2-host/. After installing, I created the ~/.wsl2hosts config file and put my hosts in. Now wsl2host will add entries to the windows hosts file to point all these hosts to the current wsl2 ip. Works pretty well for me! Ah and one thing, you might want to deactivate the automated generation of the hosts file inside of wsl2, since it ended up overwriting the hosts from wsl2host with old IP adresse. To deactivate:

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
irakan commented 4 years ago

@thomasaull I followed the guide in documentation but I didn't install Acrylic, I manually edits my hosts file and add the sites. nothing else.

thomasaull commented 4 years ago

This way you need to update your host file whenever you restart the wsl, don‘t you?

valeryan commented 4 years ago

It's one of the know issues in WSL2. Acrylic Proxy causes issues https://github.com/microsoft/WSL/issues/4364. Also, none of the host file hacks you can find out there are going to allow wildcard routing like Acrylic or dnsmasq can. Manually adding the sites to your host file sucks but wsl2 is binding port 53 and causing Acrylic to crash.

nickescobedo commented 4 years ago

Yea when Acrylic was running and I didn't have WSL2 running and tried to start WSL2 it wouldn't start because something to do with creating the network adapter.

I gave up trying to get it to work unfortunately and just manually add sites to my hosts file until something works out. I appreciate your quick responses! 😄

irakan commented 4 years ago

This way you need to update your host file whenever you restart the wsl, don‘t you?

No, only once but every-time your create a site inside your parked folder, you will need to add it manually to hosts file.

Or you can use this, I have created it to append sites automatically when I do valet park, valet link etc..


1 - add this to your .bash_aliases file to intercept valet command

SETTUP_HOSTS_PATH=~/setup-hosts.sh

valet() {
    if [[ $@ == "park" || $@ == "link" ]]; then
        command valet "$@" && bash $SETTUP_HOSTS_PATH
    else
        command valet "$@"
    fi
}

2 - run source .bashrc to apply the change

3 - create setup-hosts.sh file in the same place as SETTUP_HOSTS_PATH and put:

#!/bin/sh
WINDOWS_HOSTS_PATH=/mnt/c/Windows/System32/drivers/etc/hosts

function add() {
   grep -qxF "127.0.0.1 $1.test" $WINDOWS_HOSTS_PATH || echo "127.0.0.1 $1.test" >> $WINDOWS_HOSTS_PATH
}

valet paths | grep -oP '"(.*?)"' | tr -d '"' | while read -r line ; do
    cd $line

    for f in * ; do
        add $f
    done

done

4 - go to C:\Windows\System32\drivers\etc and right click on hosts => properties => security and give your user write permission.

thomasaull commented 4 years ago

Ah of course, I did setup my host file to point at the WSL IP, but I can just use localhost, since it will also resolved by WSL. That makes a whole lot more sense. And many thanks for your script @irakan

Himakar-PV commented 4 years ago

Hi, I downloaded Microsoft Windows [Version 10.0.19592.1001] through insider (Fast)

It has vhost issue as explained below :

I have two projects

  1. Laravel (var/www/html/laravel/..)
  2. Pimcore (var/www/html/pimcore/..)

I have two configs under /etc/apache2/sites-available

  1. laravel.dev.config
  2. pimcore.dev.config

NOTE : Both are not enabled yet

In hosts file (/etc/hosts) I added below lines : 127.0.0.1 laravel.dev 127.0.0.1 pimcore.dev ::1 pimcore.dev ::1 laravel.dev

Now in browser when I type "localhost", it loads default Apache page.

Scenario 1 : Run below commands sudo a2ensite laravel.dev.config sudo service apache2 restart Type localhost in browser it loads Laravel project Type laravel.dev in browser, loads nothing

Scenario 2 : Run below commands sudo a2dissite laravel.dev.config sudo a2ensite pimcore.dev.config sudo service apache2 restart Type localhost in browser it loads pimcore project Type pimcore.dev in browser, loads nothing

Scenario 3 : Run below commands sudo a2ensite pimcore.dev.config sudo a2ensite laravel.dev.config sudo service apavhe2 restart Type localhost in browser it loads Laravel project Type laravel.dev in browser, loads nothing Type pimcore.dev in browser, loads nothing. I wonder how localhost is loading one of the projects by default !!? In scenario 3 if I enable pimcore.dev.config after laravel.dev.config then localhost is loading Laravel project instead of pimcore by default !!!

I am ready to screen share if anyone is ready to help. Thank you.

valeryan commented 4 years ago

@Himakar-PV I am not sure what this problem has to do with Valet WSL. Maybe you are wanting to create issue on the WSL repo?

Himakar-PV commented 4 years ago

@Himakar-PV I am not sure what this problem has to do with Valet WSL. Maybe you are wanting to create issue on the WSL repo?

Yes it's regarding WSL 2 not valet, sorry.

mkantautas commented 4 years ago

After moving to WSL2 I've uninstalled acrylic as it was conflicting with other ap (can't recall which).

Also, I've simply forwarded my domain via windows hosts file, like: 127.0.0.1 yoursite.test

On WSL1 I had my apps sitting on windows native system, after wsl2 my npm run watch etc. stopped working and IDE(installing on windows) couldn't sync with the app files any longer. I've moved all my apps to the wsl2 dir now and this was resolved, but IDE(installed on win - phpstorm) is still syncing rather slow with the path on some scenarios - e.g. when a new file is created, it's no longer snappy until the IDE detects the newly created file on the app dir.

Also, another issue is I can't workaround no longer to make eslint working on wsl2, which I had working with wsl on IDE(phpstorm) level at least. For this reason, I've tried switching to vscode(it's a MS product itself so it has great compatibility with WSL2), but feature-wise it's such a huge step back so trying to fix my phpstorm setup on WSL2 :)

muodov commented 4 years ago

Now that WSL2 is released, is there any known workaround to do wildcard resolution with WSL2?

valeryan commented 4 years ago

I don't know if dnsmasq will work yet. I will have to check into it. https://github.com/microsoft/WSL/issues/4592

ghost commented 4 years ago

I'm also experiencing the same issue running build 2004 from the slow ring and as a few of you have pointed out, it's looking more and more like the issue is with Acrylic binding to port 53, disabling the acrylic service allows WSL2 to function properly again, has anyone found a workaround for this as I require Acrylic for use with setting up Valet for proxying *.test domains

valeryan commented 4 years ago

Acrylic always binds to port 53, the issues is that now in wsl2 dnsmasq is also binding port 53 and that is getting bound on the host system. You can try disabling anything in wsl2 that would attempt to bind port 53. That is to say, go into some setting files, etc and disable dnsmasq and make sure it does not start when wsl boots. I don't have any computers I can move to the slow or fast ring right now to do additional testing. When the 2004 update finally releases I will spend some time trying to get things working again.

devcircus commented 4 years ago

I know there are a lot of workarounds for automatically updating the windows hosts file, just wanted to leave mine here. Instead of using the valet link command, I have a bash function named vlink that calls valet link then calls a powershell script that adds the "127.0.0.1 mysite.test" line to the windows host file, using the name of the current folder. I know little about powershell scripting, but here's what I use.

# addCurrentToHosts.ps1

$name = Split-Path -Path (Get-Location) -Leaf
$string = "127.0.0.1" + " " + $name + ".test"
sudo Add-Content -Path C:\Windows\System32\drivers\etc\hosts -Value $string

Due to windows permissions on the hosts file, you can install the "sudo" package for windows via scoop or chocolatey. That way, you don't have to have your terminal open as an administrator, and when you call vlink you can just press "alt + y" when the permission window appears.

The bash function for vlink is:

function vlink {
    valet link
    pwsh.exe -File 'C:\<location>\<of>\addCurrentToHosts.ps1'
}
besrabasant commented 4 years ago

adding full domain name instead of a wildcard entry to windows hosts file worked for me

127.0.0.1   phpinfo.test

The reason why wildcard does not work in the answer given here https://superuser.com/questions/135595/using-wildcards-in-names-in-windows-hosts-file

devcircus commented 4 years ago

Definitely works if you manually open and add it each time.

manuelojeda commented 4 years ago

adding full domain name instead of a wildcard entry to windows hosts file worked for me

127.0.0.1     phpinfo.test

The reason why wildcard does not work in the answer given here https://superuser.com/questions/135595/using-wildcards-in-names-in-windows-hosts-file

This saved me, thanks!

artistro08 commented 4 years ago

adding full domain name instead of a wildcard entry to windows hosts file worked for me

127.0.0.1     phpinfo.test

The reason why wildcard does not work in the answer given here https://superuser.com/questions/135595/using-wildcards-in-names-in-windows-hosts-file

This worked for me too. Works like a charm

ghost commented 4 years ago

Working here for me using Acrylic proxy and using loopback address of Windows host (127.0.1.1) as resolver. Acrylic needs to be configured to allow incoming connections from 172.16.*.

manuelojeda commented 4 years ago

Working here for me using Acrylic proxy and using loopback address of Windows host (127.0.1.1) as resolver. Acrylic needs to be configured to allow incoming connections from 172.16.*.

@cubikca Do you have some guide to do that?

ghost commented 4 years ago

Sorry for the confusion, but it appears I am confused as well. I've tried so many things that I no longer remember everything. So sorry for planting false hope: if you want a properly behaving Linux, you'll need to install a VM.

The short version of the story:

Conclusion: WSL has too much weirdness to work like a proper Linux host. Systemd support is absolutely necessary but that opens a huge support can of worms since many programs will break (like valet-linux) without it being clear why. The fact is, Systemd can only work if it starts at boot time. And that means putting it in a VM.

artistro08 commented 4 years ago

Sorry for the confusion, but it appears I am confused as well. I've tried so many things that I no longer remember everything. So sorry for planting false hope: if you want a properly behaving Linux, you'll need to install a VM.

The short version of the story:

  • There's no loopback connection between WSL and the Windows host
  • A setup called systemd-genie further added to the confusion by separating the Windows and Linux hosts into two separate hostnames and communicating through the loopback. I'm not really clear on what ended up happening there, but I ended up with an address of 127.0.1.1 for a host with the same name as my Windows host. It wasn't.
  • The not-Windows host was running dnsmasq and so appeared to respond like Acrylic would
  • I have no idea where the not-Windows host is... systemd-genie installs some kind of weird inner environment to start up systemd with a PID of 1. I think the loopback connects the genie "bottle" with the WSL host.

Conclusion: WSL has too much weirdness to work like a proper Linux host. Systemd support is absolutely necessary but that opens a huge support can of worms since many programs will break (like valet-linux) without it being clear why. The fact is, Systemd can only work if it starts at boot time. And that means putting it in a VM.

So I was actually able to get this working with systemd-genie. My steps were as follows:

I've been running this commercially so no drawbacks that I can see.

ghost commented 4 years ago

Sorry for the confusion, but it appears I am confused as well. I've tried so many things that I no longer remember everything. So sorry for planting false hope: if you want a properly behaving Linux, you'll need to install a VM. The short version of the story:

  • There's no loopback connection between WSL and the Windows host
  • A setup called systemd-genie further added to the confusion by separating the Windows and Linux hosts into two separate hostnames and communicating through the loopback. I'm not really clear on what ended up happening there, but I ended up with an address of 127.0.1.1 for a host with the same name as my Windows host. It wasn't.
  • The not-Windows host was running dnsmasq and so appeared to respond like Acrylic would
  • I have no idea where the not-Windows host is... systemd-genie installs some kind of weird inner environment to start up systemd with a PID of 1. I think the loopback connects the genie "bottle" with the WSL host.

Conclusion: WSL has too much weirdness to work like a proper Linux host. Systemd support is absolutely necessary but that opens a huge support can of worms since many programs will break (like valet-linux) without it being clear why. The fact is, Systemd can only work if it starts at boot time. And that means putting it in a VM.

So I was actually able to get this working with systemd-genie. My steps were as follows:

  • Install Ubuntu 20.04 WSL
  • Install valet-linux
  • install systemd-genie from source
  • adjust the hosts file for windows (e.g. 127.0.0.1 test.test)
  • profit.

I've been running this commercially so no drawbacks that I can see.

Just to be sure: you still need to add every host to hosts file on Windows, right?

devcircus commented 4 years ago

Correct. I'm not sure what the above is claiming to solve. This already works out-of-the-box if you add each site to your hosts file. The whole issue is about not having to add each site manually. Currently, due to wsl issues, this doesn't work, so we just add every site to hosts.

insign commented 4 years ago

I think maybe we can use DNSCrypt-proxy to redirect using cloaking rules. It worked on linux. I'll try then edit this comment.

plakhin commented 4 years ago

The solution is to bind dnsmasq to different port, smth like 5353. Then use smth like YogaDNS and configure it to resolve .test using 127.0.0.1:5353 (I guess dnsmasq should be accessible by 127.0.0.1 ip address as other WSL2 services likes nginx, but I don't have WSL2 installed at the moment so can't check). Currently I'm running Ubuntu inside VirtualBox VM for local development and using dnsmasq+YogaDNS to resolve .test, works great.

The biggest problem with WSL2 is stil... filesystem access performance. 1) If you store your project in windows filesystem and use /mnt/c/... paths you're getting native performance in Windows IDE which is great, but inside WSL2 it performs extremely slow. 2) If you store your project inside WSL2 on its filesystem and access files from windows by \\wsl$\Ubuntu\... you have really great performance inside WSL2, faster than inside VirtualBox VM, but accessing files from Windows IDE becomes paing because it is really slow and doesn't support filesystem notifications, so you have to manually refresh file list each time new file or folder is created and so on. I know there is VS Code Remote WSL extension which is actually great, but I'm not using VS Code.

As soon as filesystem access performance issue will be resolved, I'll move to WSL2 + Valet + Docker (for MySQL, Postgre, Redis etc.) for local development without any doubt.

valeryan commented 4 years ago

My system finally upgraded to windows 2004. I will try to look into getting this working but Microsoft has not really given any indications that they find it worthwhile to fix localhost forwarding or using dnsmasq. I am not super optimistic at this point but I think the answer will be something similar to making sure that dnsmasq does not bind port 53 so that acrylic and work or figuring out how to provide some other kind of interoperable DNS solution.

artistro08 commented 4 years ago

My system finally upgraded to windows 2004. I will try to look into getting this working but Microsoft has not really given any indications that they find it worthwhile to fix localhost forwarding or using dnsmasq. I am not super optimistic at this point but I think the answer will be something similar to making sure that dnsmasq does not bind port 53 so that acrylic and work or figuring out how to provide some other kind of interoperable DNS solution.

You might look into editing the hosts file manually. I have a script that watches the parked directory and creates an entry whenever there is a new folder in there.

valeryan commented 4 years ago

Host file hacks do not support wildcard domains and will never be capable of providing the coverage of a dns proxy. If your project only uses a simple single domain layer then something like domain.test in your host file is enough but many projects need support for *.domain.test which is not possible with host file entries.