
Adding Multiple tld's to valet
So, all of us use some kind of local development setup. It may be LAMP, WAMP(windows), XAMPP, Vagrant, etc. I used to use XAMPP a lot, then I switched to Vagrant and now finally Valet.
After using Valet, I can say, it offers a great development experience. Local dev enviroment setup is a breeze with Valet. Just go to your project root and run valet link
and you are good to go (You can find more in the docs here). Unluckily, the default project only supports macOS, but there are fork’s of the project for other OSes also.
- valet-linux for Linux
- valet-windows for Windows
Adding more than one tld
So, by default, Valet serves your projects using the .test
TLD, i.e. if you have a project named example, it will be served under example.test
. You can obviously change the tld to anything you want using the command valet domain <tld-name>
. But there’s a catch. Valet let’s you serve all your projects under one tld only. But what if you want your projects to be served under multiple tld’s. Let’s say, you want to have both .test
and .dev
. And later, you also want to add .app
. So, here’s a solution (more of like a hack) to add multiple tld’s to valet.
The hosts configuration for Valet saved in the file /etc/dnsmasq.d/valet
. If you open that file, you will find an entry like
address=/.test/127.0.0.1
This tells Valet to resolve all .test
domain names to localhost
. Now, to add a second tld, you can either do
address=/.test/.dev/127.0.0.1
or
address=/.test/127.0.0.1
address=/.dev/127.0.0.1
This tells Valet to resolve both, .test
and .dev
domain names to localhost
.
Next step, you have to restart dnsmasq (not Valet) by running the command sudo service dnsmasq restart
. This reconfigures dnsmasq to accept your newly added tld.
Now for last step, link your site with the new tld by running valet link example.dev
. Do not forget to add the tld after the name. That’s it.
Now you can find your site served under both example.test
and example.dev
.
Note:- For any site to be served under your new tld, add the tld to the domain name while running valet link
.
Happy Coding!!!