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.

💡
Why .test and not .local?

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.

1

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
2

macOS / Linux

sudo nano /etc/hosts

Add this line at the end:

127.0.0.1    abc.test

Save: Ctrl+OEnterCtrl+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>
💡
Replace the path

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

Navigate to http://abc.test

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.test to your hosts file
  • Created a virtual host config (Apache or Nginx)
  • Restarted your web server
  • http://abc.test now 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.