Greetings!
This thread is here to help Windows-based developers to use wildcards in their hosts file - and if you haven’t read it yet, I urge you to read Bruno Skvorc’s excellent guide on setting up automatic Virtual Hosts first. (TL;DR: create a project folder, point your browser to project.local.dev, and code! No more hosts file to edit.)
I will only cover the dnsmasq part, which is unavailable on Windows.
Dnsmasq is a simple DNS server that routes domains to an IP. In Windows, we have Acrylic, which is even easier to set up than dnsmasq (and doesn’t crash your network drivers in the process). It installs itself as a Windows service.
First, install Acrylic, and make sure to remember where you install it (you might want to “Quick Access” that said location). By default it is C:\Program Files(x86)\Acrylic DNS Proxy.
Press the Windows key, type in Services, locate Acrylic and make sure it is started. You may also enable service auto-startup when Windows boots up, by right-clicking on the service and heading to properties).
Next, open up Notepad or your favorite editor (as admin if in sensible location - like program files), head to your installation folder, open the AcrylicHosts.txt file, and at the bottom add your desired IP matching a domain name:
[...]
192.168.10.10 *.projects.dev # projects in vagrant/projects
192.168.10.10 *.symfony.dev # access symfony app_dev.php in web/ folder
192.168.10.10 *.symfony.app # access symfony app.php in web/ folder
[...]
192.168.10.20 *.dev # register one domain for one Vagrant box,
# anything preceeding the * will just work!
[...]
Save and exit. Don’t forget to execute RestartAcrylicService.bat to make your changes effective. Make sure everything works by opening up a Terminal/Command Prompt window and type in:
ping am.i.a.wildcard.dev
ping my.symfony.app
etc...
You should get 100% success ;).
How to use:
In your Vagrant box folder, create a directory that will host your projects, and inside create your effective project folder (I am using Git Bash here):
# /c/vagrant/mybox
$ mkdir -p projects/project_name
The next thing to do is configure Nginx’s or Apache’s Vhosts in the likes of Bruno’s guide in your Vagrant box, and then happily point your browser to project_name.local.dev.
If you check your default hosts file, you will notice that every entry has been commented out. So long hosts file!
Note:
Acrylic provides more powerful tools than explained here, be sure to read the AcrylicHosts file and the AcrylicConfiguration file in Acrylic’s folder.
Hope it helps
Happy (quickly set up) coding!