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.
Locahl Team
Table of Contents
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
1. Add the domain to your hosts file:
127.0.0.1 mysite.test2. Flush DNS β on Mac or on Windows. 3. Create a virtual host in your stack pointing mysite.test to the WordPress directory (MAMP/XAMPP Apache vhost, or a Docker/Nginx server block). 4. Tell WordPress its URL in wp-config.php:
define('WP_HOME', 'http://mysite.test');
define('WP_SITEURL', 'http://mysite.test');5. Open http://mysite.test and 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.
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. Locahl 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._
Ready to simplify your workflow?
Stop wasting time with the terminal. Locahl lets you manage your hosts file in a few clicks, with automatic validation and no risk of errors.
- Intuitive visual interface
- Automatic DNS flush
- Multi-environment management
- Automatic backups
- JSON Import/Export
Reader Reviews
"Set up mysite.test for my WordPress build in minutes. So much cleaner than localhost:8888."
June 13, 2026
"The WP_HOME / WP_SITEURL tip made my .test domain work perfectly with MAMP."
June 11, 2026
"Great walkthrough. A multisite subdomain example would round it out."
June 9, 2026
Frequently Asked Questions
How do I use a custom domain for local WordPress development?
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.
What domain should I use for local WordPress?
Use a .test domain. It is reserved for testing and will not clash with real domains or force HTTPS like .dev does.
Why not just use localhost for WordPress?
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.
Do I need to flush DNS after adding the hosts entry?
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)
Which TLD to use for local development: prefer .test, avoid .dev and .local. Why .test is reserved, how to map it in the hosts file, and HTTPS tips.
Locahl Team
Developer tools team
Hosts File Setup for Laravel and WordPress
Configure hosts files for Laravel Valet, Herd and WordPress local development with .test domains, multisite setups and best practices.
Locahl Team
Best Hosts File Editors for Windows (2026)
The best hosts file editors for Windows in 2026: Locahl, Notepad as admin, Hosts File Editor+, SwitchHosts and BlueLife Hosts Editor. Pros, cons and when to use each.
Locahl Team
Developer tools team
Wildcard Local Domains: hosts File Limits & dnsmasq
The hosts file does not support wildcards like *.myapp.test. Learn why, and how to set up wildcard local domains with dnsmasq on macOS and Linux.
Locahl Team
Developer tools team
Test a WordPress Site Before DNS Propagation
Preview and test a WordPress site on a new server before DNS propagation using the hosts file. Map your real domain to the new IP, verify, then switch DNS safely.
Locahl Team
Developer tools team