How to use a custom domain with @wordpress/env


Introduction

By default, @wordpress/env starts a server on localhost:8888. This article will show you how to make it start on a custom domain, e.g. testing.local.

Method

Add domain entries you’d like to use to /etc/hosts:

127.0.0.1 testing.local en.testing.local es.testing.local

Setup the following keys in .wp-env.json:

{
	...
	"config": {
		"WP_SITEURL": "http://testing.local",
		"WP_HOME": "http://testing.local"
	},
	"env": {
		"development": {
			"port": 80
		}
	}
	...
}

And now after running wp-env start, the site will be accessible on testing.local.