Switch Laravel Valet from .dev to .test in three easy steps

Chrome and Safari began forcing https for the .dev domain because someone apparently thought it was a good idea to register as a public TLD. Laravel Valet only produces self-signed SSL certificates though, so I want to keep my local installations served as http. Guess it's time to switch TLDs!

Oh, and don't try to use .local on a Mac because it conflicts with Bonjour local networking. I discovered this with 30 minutes of wasted effort. .test is the way to go.

First, run:

valet domain test

Switch Valet to using the .test domain, which will also update dnsmasq accordingly. Don't try to edit dnsmasq configuration on your own — there are too many ways to go wrong.

Second, run:

wp package install wp-cli/find-command

Install wp-cli/find-command to find all WordPress installs in your Laravel project directory. It's convenient for running one WP-CLI command against all WordPress installs.

Third, run:

wp find ~/projects --field=wp_path | xargs -I % wp --path=% search-replace '.dev' '.test' --all-tables

Run wp search-replace against all WordPress installs to replace instances of '.dev' with '.test'. ~/projects is my Valet project directory, and --all-tables ensures the procedure is run against all database tables.

Et voila! You've switched Laravel Valet from .dev to .test in three easy steps.

Map a custom domain with Laravel Valet

Laravel Valet serves *.dev domains by default. But what if you need to host hack the production domain to your project? As it turns out, it’s easier than you’d expect it to be.

First, add the record for the domain to your /etc/hosts file:

sudo echo '127.0.0.1 my-project.com' >> /etc/hosts

Then, in your parked directory, create a symlink with the domain you want to serve:

$ cd ~/projects/
$ valet park
This directory has been added to Valet's paths.
$ mkdir my-project
# my-project.dev is now served by Valet
$ ln -s my-project my-project.com
# my-project.com is now served by Valet

Valet’s Nginx configuration handles all requests by default, so don’t bother creating a custom Nginx config file. Having it serve your specific domain is only a matter of making sure Valet knows where to find your project directory, given its auto-discovery behavior.