Valet (Laravel): DNS address can not be found

sseraluck picture sseraluck · May 11, 2016 · Viewed 15.6k times · Source

I'm trying out Valet, it looks really nice from what I've heard.

I've been trough the "whole" installation process, Valet is succesfully installed.

But when I cd into my projects file and enter valet park and browse to http://blog.dev, I get "The DNS server address of blog.dev can not be found."

I have no idea what I'm doing wrong. :)

Answer

Ben Swinburne picture Ben Swinburne · May 12, 2016

When you run valet install it attempts to install dnsmasq. It requires sudo privileges.

You can check that it's installed and running using

brew services list

You should see something like

dnsmasq started root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

You may however need to tap brew/services first

brew tap homebrew/services

If it's not there, run

brew install dnsmasq
brew services start dnsmasq

Run valet install again to set up dnsmasq and keep an eye out for any errors. What this should do is append a line to the bottom of /usr/local/etc/dnsmasq.conf similar to

conf-file=/Users/{YOURUSER}/.valet/dnsmasq.conf

/Users/{YOURUSER}/.valet/dnsmasq.conf then should contain

address=/.dev/127.0.0.1

Check that your dns server is responding to requests

dig testing.dev @127.0.0.1

You should see a response like

;; ANSWER SECTION:
testing.dev. 0 IN   A   127.0.0.1

To actually ensure that your Mac knows that it should resolve *.dev using your local DNS server, it need to be told to do so. Valet also handles this for you but you can check if it's done it's job by doing the following.

Inside the directory /etc/resolver, there should be a file entitled dev with the following contents

nameserver 127.0.0.1

This creates a custom DNS resolver for *.dev and points all requests at your local DNS server.

Restart dnsmasq with either of the following commands and then give it a try again.

// this
brew services restart dnsmasq

// or this
sudo launchctl stop homebrew.mxcl.dnsmasq
sudo launchctl start homebrew.mxcl.dnsmasq

If this is all working, you should be able to ping anything.dev

ping anything.dev

PING anything.dev (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.039 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.081 ms

That ensures the DNS related bits are working.


Ultimately the question is about DNS related problems but as this started off as a here's everything you need to have tried, I'll leave this below. That said, if you're unable to ping something.dev or get an error like "The DNS server address of blog.dev can not be found." as per the OP, it's something above to do with DNS which needs resolving.

Since Caddy serves websites on port 80, you need to ensure that nothing else is running on port 80.

sudo lsof -n -i:80 | grep LISTEN

Ideally this should return caddy if valet is running as expected. You want to see the example below or nothing ideally; nothing because it means we can just start Valet.

caddy     76234 root    3u  IPv6 0x4f871f962e84fa95      0t0  TCP *:http (LISTEN)

You may see other webservers, such as Apache or Nginx (and their child processes, _www and nobody) in the example below.

httpd       79     root    4u  IPv6 0xf4641199930063c5      0t0  TCP *:http (LISTEN)
httpd      239     _www    4u  IPv6 0xf4641199930063c5      0t0  TCP *:http (LISTEN)
nginx     4837     root    6u  IPv4 0xf4641199a4e8e915      0t0  TCP 127.0.0.1:http (LISTEN)
nginx     4838   nobody    6u  IPv4 0xf4641199a4e8e915      0t0  TCP 127.0.0.1:http (LISTEN)

Assuming you've installed Nginx with homebrew you can run the following to stop it.

brew services stop nginx

OSX ships with Apache installed so you can stop with with the following if it's running.

sudo apachectl stop

At this point you can likely start Valet with valet start and it'll work.

You may get a further error which is caused by PHP being installed without FPM. You can check this using

brew info php70 | grep php70-fpm

Which should yield something along the lines of

The control script is located at /usr/local/opt/php70/sbin/php70-fpm

If it doesn't appear to be installed, use the following.

brew uninstall homebrew/php/php70
brew install homebrew/php/php70 --with-fpm
valet restart