I am in the process of setting up a development environment on a new machine and one of the things I decided to do is route all .dev domains to my local (built-in) Apache web server while I route all .app domains to my Laravel Homestead Vagrant environment.
To never have to monkey with your hosts file, Apache can be configured to serve any .dev domain that matches an existing folder name from a base directory. The Homestead.yaml file handles domain-to-directory mapping explicitly for the Laravel Vagrant environment.
This ended up being really easy – the things I needed to know were:
- what to put into the dnsmasq config
- how to stop and start dnsmasq
brew install dnsmasq
From there, you’ll follow the recommended step from the installer output to create your config file:
cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
Now open that file in your favorite editor and replace its contents with:
# General sites (Apache)
# Laravel Homestead (Vagrant)
Lastly, stop and start Dnsmasq to apply the changes in the config:
sudo launchctl stop homebrew.mxcl.dnsmasq
sudo launchctl start homebrew.mxcl.dnsmasq
That’s it! Or at least that’s all it took for me. I hope your experience is as easy as mine was.
Now to set up Apache to handle anything with a .dev suffix from a matching directory from my Sites dir. Add this to your vhost configuration:
Options Indexes MultiViews FollowSymLinks
Require all granted
Restart Apache with errors returned to find errors in your config:
sudo apachectl -e info -k restart
If you get a 403 error when loading your site in a browser, make sure that every dir in the chain to the web root has the “execute” permission. Add it via:
chmod +x dirname
That should do it.
Improvements/corrections to the above solution are welcome. Enjoy!