Set Up Domain Name with XAMPP in 10 Steps
In this article
Setting up a custom domain name with XAMPP helps you test websites as if they were live, making development easier and more realistic. This guide walks you through the process step by step, ensuring a clear setup without unnecessary complexity. You’ll need a local development environment with XAMPP already installed and a basic understanding of how web servers work.
What You'll Need
- XAMPP installed on your system
- Apache and MySQL running in XAMPP
- Access to the hosts file on your machine
- Basic knowledge of HTML and server setup
Step-by-Step
- Open XAMPP Control Panel
Launch the XAMPP application and ensure that Apache is running. If it’s not running, start it by clicking the Start button next to Apache. - Choose a domain name
Pick a domain name for your local setup, likemyproject.local. This will be used in your browser to access the site. - Edit the Hosts File
Open the hosts file in a text editor with administrator privileges. The file is located at: - Windows:C:\Windows\System32\drivers\etc\hosts- macOS/Linux:/etc/hostsAdd the following line at the end of the file:127.0.0.1 myproject.localSave the changes. - Create a New Folder in htdocs
Navigate to the XAMPP installation folder, then tohtdocs. Create a new folder namedmyproject(or whatever you chose earlier). - Add Your Website Files
Place your website files (HTML, CSS, JS, etc.) into themyprojectfolder. This is the root of your local site. - Create a Virtual Host in Apache
Open the Apache configuration file for virtual hosts. It's usually located at:C:\xampp\apache\conf\extra\httpd-vhosts.confAdd the following block at the end of the file:<VirtualHost *:80> ServerName myproject.local DocumentRoot "C:/xampp/htdocs/myproject" <Directory "C:/xampp/htdocs/myproject" Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>Save the file. - Restart Apache
Go back to the XAMPP Control Panel and click the Stop button next to Apache, then click Start again to apply the changes. - Open Your Browser
Typemyproject.localinto the address bar of your browser and press Enter. If everything is set up correctly, your website should appear. - Test Your Setup
Try creating a simpleindex.htmlfile and loading it through your custom domain to ensure the setup is working as expected. - Verify DNS Settings
Open your browser’s developer tools and check network requests to confirm the domain resolves correctly and is loading from the local server.
Common Mistakes
Many people forget to restart Apache after making configuration changes. Always restart Apache after editing the hosts or Apache configuration files. Also, not using 127.0.0.1 in the hosts file can prevent the domain from resolving locally.
Tips
- Use a browser extension like Host Admin or Localhost Domain Switcher to easily manage custom domains for development.
- Always back up your hosts file before editing it. Mistakes can lead to system-wide connectivity issues.
- Use descriptive domain names for multiple projects, such as
blog.local,portfolio.local, etc., to keep things organized. - For SSL, consider using a local HTTPS certificate setup like https-localhost.
Troubleshooting
If your custom domain does not load, first check that Apache is running and that you’ve saved and restarted it after configuration changes. Confirm the hosts file entry is correct and that no typos are present. Flush your DNS or restart your browser to ensure your changes take effect. If you still see an error, try accessing localhost/myproject to see if the site loads normally via the default setup.
Frequently Asked Questions
Can I use my real domain name?
Yes, but you must point it to your local machine’s IP address in DNS settings, which is not practical for most development workflows.
Why am I getting a 403 Forbidden or 404 Not Found error?
Check the file permissions in the htdocs directory and ensure the correct path is set in the virtual host configuration.
Can I have multiple custom domains?
Yes, by adding multiple entries to the hosts file and virtual hosts configuration. Each domain must be mapped to a unique folder in htdocs.
Do I need to edit the hosts file every time I work on a new project?
Yes, but you can automate the process using scripts or tools like Hostsfile to streamline the workflow.
Why does my custom domain still load the default server page?
Ensure Apache is restarted after configuration changes and that the virtual host port (80) is not being used by another service.
Why am I redirected to another page or an error site?
Some browsers cache DNS settings. Clear your browser’s cache or try a different browser to verify the domain is resolving correctly.