When developing websites locally with XAMPP, using localhost
as your address works fine, but it's often nicer and more professional to use a custom domain like myapp.test
. This tutorial shows you how to do that on a Mac.
Why Use a Custom Domain?
-
Easier to remember than
localhost
-
Mimics a real domain for better testing
-
Supports virtual hosting for multiple projects
1. Edit Your Hosts File
This makes your Mac recognize a custom domain name.
-
Open Terminal and run:
-
Enter your Mac password.
-
At the bottom, add:
-
Save and exit (
Ctrl + O
, Enter, thenCtrl + X
).
2. Create Your Project Folder
XAMPP stores websites in the htdocs directory.
3. Add a Sample index.html
Create a simple page to test your domain:
Paste this:
Save (Ctrl + O
, Enter) and exit (Ctrl + X
).
4. Configure Apache Virtual Hosts
Open the Virtual Hosts config file:
Add this block at the bottom:
Save and exit.
5. Enable Virtual Hosts in Apache
Open the main Apache config file:
Find this line:
Remove the #
so it becomes:
Save and exit.
6. Restart Apache
Restart Apache with:
(or restart from the XAMPP Control Panel).
7. Test Your Custom Domain
Open your browser and go to:
✅ You should now see your “It works! 🎉” page.