Running a project on localhost:8000 gets old fast — especially when you're testing cookies, subdomains, or HTTPS. A custom .test domain is cleaner, closer to production, and takes about five minutes to set up. Here's how.
The .test TLD is reserved for local testing and will never be registered publicly. .local is claimed by mDNS/Bonjour on macOS and can cause slow DNS lookups.
Step 1: Edit Your Hosts File
The hosts file tells your computer how to resolve domain names locally — before any DNS request ever leaves your machine.
Windows
Open Notepad as Administrator, then open:
C:\Windows\System32\drivers\etc\hosts
Add this line at the end:
127.0.0.1 abc.test
macOS / Linux
sudo nano /etc/hosts
Add this line at the end:
127.0.0.1 abc.test
Save: Ctrl+O → Enter → Ctrl+X
Step 2: Configure Your Web Server
Tell your web server to serve your project when it receives a request for abc.test.
Apache Virtual Host
Open your vhosts config and add:
<VirtualHost *:80>
ServerName abc.test
DocumentRoot "/path/to/your/project/public"
<Directory "/path/to/your/project/public">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Swap /path/to/your/project/public with your actual project directory — e.g. /var/www/myapp/public for a Laravel project.
Restart Apache:
# Linux / macOS
sudo systemctl restart apache2
# XAMPP (Windows) — use the Control Panel
Nginx Server Block
server {
listen 80;
server_name abc.test;
root /path/to/your/project/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Enable and reload:
sudo ln -s /etc/nginx/sites-available/abc.test /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Step 3: Open in Browser
You should see your local project. If the page doesn't load, double-check the hosts file entry and make sure your web server is running.
Summary
- Added
127.0.0.1 abc.testto your hosts file - Created a virtual host config (Apache or Nginx)
- Restarted your web server
http://abc.testnow serves your local project
TL;DR
Two files to edit: your OS hosts file (add 127.0.0.1 abc.test) and your web server's vhost config (point abc.test at your project's public folder). Restart the server. Done.