2

I am trying to make Valet and Local work together on Mac but with no luck. There's probably a DNS conflict with dnsmasq.
For example I have these two sites, with the default configuration setup:


Site on Local:

local-site.local

Local is an environment optimized for setting up WordPress sites locally. I am using all the default settings. Local can be downloaded here: https://localwp.com/

Site on Valet:

valet-site.test

There's nothing special in the Valet configuration either:

/Users/goran/.config/valet/config.json

{
    "tld": "test",
    "paths": [
        "/Users/goran/.config/valet/Sites",
        "/Users/goran/projects"
    ]
}

/Users/goran/.config/valet/dnsmasq.d/tld-test.conf

address=/.test/127.0.0.1
listen-address=127.0.0.1



Note: Both sites have different suffixes, so suffixes shouldn't be an issue.

Scenario #1

Start both Valet and Local

Results:

  • Valet site works fine
  • Local site shows "502 Bad Gateway" error from nginx.

When I open Local it shows this error:

"There is a port conflict with this site's domain."

This is probably returned from Valet, it probably has DNS priority over Local.

Scenario #2

Start only Local

Results:

  • Local site works fine
  • Valet site shows an error (as expected since Valet is not started). It's interesting that this error comes from Local:

404 Site Not Found The site you requested does not have an associated route in Local. If you continue to get this message after refreshing, try restarting the Local site.

It looks like something is wrong with DNS setup, but I'm not sure what exactly.

gradosevic
  • 4,809
  • 2
  • 36
  • 51
  • What is `Local`? Valet also is a local installation. Please post your config files. – Roman Mar 21 '21 at 08:33
  • Hi @Roman, Thanks for asking, Local is an environment for developing and testing WP sites locally. Please check the question description above, I added some more details about it. – gradosevic Mar 22 '21 at 10:03

4 Answers4

1

This isn't a DNS issue, as it says in the error - they're both attempting to use the same port. It's a port conflict, they're likely both trying to use port 80.

Just change one, the other, or both to use different ports.

Pobtastic
  • 262
  • 2
  • 9
  • You're probably right, it could be something with ports. Since Local doesn't work on anything other than port 80, they say this on Local's forum: "In order for Local to use pretty URLs, it needs to use port 80", I think my only chance is to find out how to make Valet work on a different port. – gradosevic Mar 24 '21 at 07:20
  • You have options; https://github.com/marcusmyers/docker-valet is a thing, you could just use this and have it on any port you like? – Pobtastic Mar 24 '21 at 08:31
  • Still not found the right solution, but your ideas were very helpful to at least identify the issue. Thanks! – gradosevic Mar 25 '21 at 12:07
1

I encountered the same issue too, what I did was to stop Laravel Valet using the valet stop command, then start Local. Once Local and my sites on Local are up, I started valet using the valet start command and I can now access my sites using valet and local.

My domain suffix is test for valet and local for Local.

1

I ended up with a workaround solution where you need to make sure to do things in the following steps:

  1. Make sure both Local and Valet are turned off
  2. Start Local site(s)
  3. Start Valet

In this order Local DNSMasq will run first and Valet second. When Vale DNSMasq runs after it does not break Local changes, so this can be used as a workaround.

In some cases you will see that sites on Local are not working (showing Valet site not found error) and in such cases you will need to do things in the following order:

  1. Stop Valet
  2. Stop Local site(s)
  3. Start Local site(s)
  4. Start Valet

This way the resetting will configure all sites back correctly, and you can use this until you want to start/stop another site on Local. No issues on adding new sites on Valet though, since Valet DNSMasq is the one that handles sites at this moment.

TIP1: Sometimes the port conflict issue still may appear in Local, but what you can do is to make sure is Valet is stopped and then restart Local site(s) and make sure they work first (by going into browser and checking) and after that you can start Valet.

TIP2: Another trick when you are unable to resolve conflict by just restarting Local site (while Valet is stopped) is to create a dummy Local site that you would use just to restarting, this may trigger the restart of DNSMasq and resolve the issue.

TIP3: You may need to wait for a 10s or so before starting Valet after Local (or just visit Local site in browser to see if it's live)

gradosevic
  • 4,809
  • 2
  • 36
  • 51
0

Another options is to use Local's localhost router mode: enter image description here

This would free up port 80 for the other application.

mikerojas
  • 2,238
  • 1
  • 4
  • 7
  • Thanks for the suggestion, but this would use localhost instead of domains and it's not a solution for me, since I use multiple sites that "talk" to each other and in some cases subdomains. – gradosevic Mar 24 '21 at 07:17