
WordPress Local Development With a .test Domain (hosts file)
Set up a local WordPress site with a clean .test domain using the hosts file. Works with LocalWP, MAMP, XAMPP and Docker. Map the domain, flush DNS, configure WP.
Manage hosts files without the terminal
ToggleHosts helps you manage environments visually on Windows, macOS, and Linux, with automatic DNS flush and backups.
One-time payment
To run a local WordPress site on a clean domain like mysite.test, map it to 127.0.0.1 in your hosts file and point your local server at the WordPress folder. This replaces ugly URLs like localhost:8888 with a real, memorable domain that behaves more like production, and it works with LocalWP, MAMP, XAMPP, and Docker.
Set up local WordPress with a .test domain
- Add the domain to your hosts file:
127.0.0.1 mysite.test- Flush DNS, on Mac or on Windows.
- Create a virtual host in your stack pointing
mysite.testto the WordPress directory (MAMP/XAMPP Apache vhost, or a Docker/Nginx server block). - Tell WordPress its URL in
wp-config.php:
define('WP_HOME', 'http://mysite.test');
define('WP_SITEURL', 'http://mysite.test');- Open
http://mysite.testand finish the WordPress install.
Why .test (not .dev or localhost)
.test is reserved by the IETF for testing, so it never collides with a real domain and browsers do not force HTTPS on it (unlike .dev). Pick the right TLD with which TLD to use for local development, and get the line format right with the hosts file syntax guide.
Per-tool notes
- LocalWP: it manages its own domains, but a hosts entry lets you align with a custom
.testname. - MAMP / XAMPP: add an Apache
<VirtualHost>withServerName mysite.testand the WPDocumentRoot. - Docker: map the port and add the hosts entry; for many subdomains use wildcard local domains with dnsmasq. See also managing the hosts file with Docker.
From local to staging or production
When you later push this local build to a staging server or production, export the WordPress database along with the files. A same-domain move needs nothing more; only if the domain changes do you run a search-replace on the stored URLs, then switch DNS and follow normal propagation. Until then, the hosts file keeps your local .test domain entirely separate from the live site.
Local HTTPS (optional)
If a plugin requires HTTPS locally, generate a trusted certificate with mkcert, see local HTTPS on Mac with mkcert, and set the URLs to https://mysite.test.
Manage multiple WordPress sites cleanly
Running several WordPress builds means several .test domains, and the hosts file gets cluttered fast. ToggleHosts keeps each project’s mapping with a one-click toggle and flushes DNS automatically, so switching between WordPress sites is instant. For a broader stack view, see hosts file for Laravel and WordPress local dev.
_Last tested: June 2026 with WordPress 6.x on macOS, Windows and Linux._
Sources and further reading
Frequently Asked Questions
Map a .test domain to 127.0.0.1 in the hosts file (e.g. 127.0.0.1 mysite.test), point your local server (MAMP/XAMPP/Docker) at the WordPress folder for that host, and set WP_HOME/WP_SITEURL to http://mysite.test.
Use a .test domain. It is reserved for testing and will not clash with real domains or force HTTPS like .dev does.
localhost works but is generic and breaks when you run several projects. A named .test domain per site is clearer and matches the eventual production URL more closely.
Yes, flush DNS so the new mapping takes effect, then load the .test domain in your browser.
Related Articles
Which TLD to Use for Local Development (.test vs .localhost)Local development
Which TLD to Use for Local Development (.test vs .localhost)
2 min read
How to Sync WSL2 with Windows Hosts File for Local Domains (2026)Local development
How to Sync WSL2 with Windows Hosts File for Local Domains (2026)
5 min read
Fix ERR_TOO_MANY_REDIRECTS with Hosts File (2026)Troubleshooting
Fix ERR_TOO_MANY_REDIRECTS with Hosts File (2026)
3 min read