valet: cURL error 6: Could not resolve: site.test (Domain name not found)
I have a laravel app and a lumen api app both installed on my local machine. The laravel app uses the lumen app to get the data, so on my .env file the laravel app has its APP_DOMAIN=http://site.test/ and it’s being used as a base_uri for the Guzzle Client class.
Everything was working smoothly not until today I got the error that says.
cURL error 6: Could not resolve: site.test (Domain name not found) (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
When I try to test the lumen url on the browser it works completely fine, as well as on postman. http://site.test/url-here it returns the json stuff that I need.
So I was wondering why isn’t being recognized by the laravel app.
Also I saw very similar issue But I don’t think adding the url on the /etc/hosts file is the right way
Any idea how to fix this? I am not quite sure if this is the right place to post this issue. So I apologize if I’m on the wrong side.
Thanks
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 27 (7 by maintainers)
You could also install an alternate Client to override the default of using CURL: http://docs.guzzlephp.org/en/latest/faq.html#does-guzzle-require-curl
I wouldn’t have expected a simple
yarn updateto do anything that’s interfering, unless it’s gone and installed some package that set some new ENV vars that CURL uses, or something that provides DNS services and now is clashing with dnsmasq or osx core. And if it does then that raises other concerns, beyond the scope of Valet. But, one way to rule it out is to delete everything yarn installed, and then remove the node_modules dir, and reboot. And if it’s from “global” tools that yarn installed, clean those up too. Maybe not “ideal”, but useful as a troubleshooting step nonetheless.Given that you said other services are able to reach site.test it means dnsmasq “is” running, so the following troubleshooting for dnsmasq is probably pointless, but I’ll leave it here for reference anyway.
DNSMASQ troubleshooting
Top 3 troubleshooting steps I’ve taken with dnsmasq issues:
digto find out what’s happening with lookupsdig
dig site.testThis should come back with something like the following. Note the “A” record pointing to 127.0.0.1, and theSERVER: 127.0.0.1in the following, and what’s different in yours.logging
Enabling logging in dnsmasq: One place to do this is in
~/.config/valet/dnsmasq.confIt should already have 2 lines in it for your configured TLD. Add the following lines, adjusting for your actual username:Then
sudo brew services stop dnsmasq && sudo brew services start dnsmasq && brew services listWhat’s the output? Does it show dnsmasq running as root? Then look in your~/Downloads/dnsmasq.logfile for any messages, particularly things pointing out problems. (Once you’ve resolved your dnsmasq issues, remove those logging entries, since it’ll just waste disk space.)OSX networking
I have had this problem several time after doing an update with brew. And I’ve forgotten the solution that works for me several times 😃
As this was one of the first things I hit with google I’m going to post why this occurs for me here.
I got the solution from here https://stackoverflow.com/questions/54688451/curl-laravel-valet-dnsmasq-not-working
Quick way to check if this is your problem is to do:
curl --versionandphp --ri curlThe versions should match. If they don’t it’s probably because brew has installed
curl-openssl. This can be removed by doing:brew uninstall curl-openssl --ignore-dependenciesMaybe there’s a way to configure the installed
curl-opensslproperly - I’ve not investigated this yet.Thanks @drbyte for the those clear instructions. I did follow all the things you listed.
Adding
127.0.0.1to System Preferences -> Network -> Advanced -> DNS solves the issue. It was blank at first (actually grayed out) So I just add it as first lookup source.Thanks!!
Thank you! I’ve been using
.localhostfor my local valet development, and haven’t experienced a single issue until this passed month where I’ve been using Guzzle in one local app to query another local app/api (both.localhost). I could manually type/visit in both apps and both would load within milliseconds, but took 2-4 minutes with Guzzle, and occasionally wouldcURL error 6: could not resolve site.localhost`.I also use a PiHole, so I put it down to something to do with the local resolution, until I found this and added
127.0.0.1to my DNS.My DNS entries are in the following order:
Guzzle/cURL are now both instantaneous!
My solution:
Just wanted to chime in and say that
brew uninstall curl-openssl --ignore-dependenciesworked for me.
Adding
127.0.0.1to the DNS server list screwed up my internet (some hosts wouldn’t resolve properly), so I removed it again.Note: you might need to add back a “real” DNS resource.
You can do that either in the System Prefs DNS pane, or add the following to your dnsmasq.conf file (you don’t need all of them, pick one or two to uncomment):
At first there was
192.168.1.1in my system preference network DNS added127.0.0.1and it solved my problem. thanks @drbyteBut i could not access other networks after that. after that i added
192.168.1.1below127.0.0.1.Now my guzzle http and browser network both working .
@ahmadabdallah you could add manually the domain to your hosts file it’s not a fix but it will just work fine
Yes and no. An even better way is to tell Dnsmasq what you preferred DNS servers are. This is easily done by creating a new config file. Example: to use Cloudflare’s 1.1.1.1 create:
~/.config/valet/dnsmasq.d/dns-cloudflare1111.confcontains:Add/remove
*.conffiles in the~/.config/valet/dnsmasq.d/directory to control your Dnsmasq configuration.**This works since Valet 2.6.0
In addition to DrByte’s reply above, make sure 127.0.0.1 is the first entry in your dns list.
So I have tried everything in this issue thread. The only thing that has worked for me is putting
127.0.0.1in my DNS entries AT THE TOPI figured out this mattered after running
dig dev-site.testand I gotSERVER: 8.8.8.8#53(8.8.8.8)Then I moved the localhost(127.0.0.1) address to the top of my DNS entries and that resolved everything for me.
dig dev-site.testnow results in:SERVER: 127.0.0.1#53(127.0.0.1)Make sure you have this at the top!!! The order matters! At least it did for me…
Hello, I just wanted to add some additional info as I ran into this as well.
I was seeing very slow requests between my Laravel applications with Curl via Guzzle. For some reason
file_get_contentsworked correctly but curl did not. In my case the Guzzle requests were actually finishing eventually, they just took ~25 seconds.After turning on verbose logging (
CURLOPT_VERBOSE) I saw the following:I verified the error occurred with both PHP 7.1 and 7.3; changing the version of PHP didn’t make a difference for me.
Adding
127.0.0.1to the DNS servers as explained above fixed my issue.