Homestead + dnsmasq

General


Homestead and dnsmasq

In Laravel, there are two out of the box setups. One is using Homestead and the other one is using Valet.

I personally prefer using Homestead because it is entirely on a virtual machine and it does not affect the host OS. If anything goes wrong, I can simply just destroy the Homestead virtual machine and start a fresh box.

One of the annoyance to me using Homestead is whenever I create a new project and giving it a unique URL, e.g. project-1.example.test, I have to edit the /etc/hosts file and add the domain to the list in order for the new URL to work.

Instead of editing the hosts file each time, I started using dnsmasq to proxy all the example.test to the IP address of the Homestead machine.

The setup is straight forward, here is my steps.

  1. brew install dnsmasq
  2. mkdir /etc/resolver
  3. touch /etc/resolver/example.test
  4. Edit /etc/resolver/example.test and add nameserver 127.0.0.1 at the top of the line.
  5. Edit /usr/local/etc/dnsmasq.conf and add address=/.example.com/<your homestead box ip> in somewhere beneath #address=/double-click.net/127.0.0.1.
  6. Start dnsmasq with sudo brew services start dnsmasq

Next | Previous

Other posts