If you have some knowledge related to websites or web development as a whole, then you might have come across the word localhost which refers to your own PC. But, did you ever wondered how you can change localhost to a domain name for XAMPP or WAMP? For those who don’t know what XAMPP/ WAMP is? These are basically software that provides the tech stack for website development, namely PHP, MySQL, Apache, PhpMyAdmin, etc.
What is localhost?
Localhost is a hostname that refers to the current computer that is accessing it. In short, Localhost refers to your computer. It is used to access the network services that are running on the host (your computer) via the loopback network interface. For example, a locally hosted website can be accessed from a web browser by the URL
http://localhost to display its homepage.
So today in this tutorial, I am going to show you how to change localhost to domain name?
How to change localhost to domain name for XAMPP?
Below is the step-by-step guide to change localhost to domain name for XAMPP, in a Windows computing environment.
Let’s, break the tutorial into 3 different parts:
- Point the custom domain to
- Add virtual hosts in apache server
- Run the server and test our work
Point the custom domain to
Now you have to add your custom domain and point it to the IP address
127.0.0.1 , which is the localhost IP address.
1. Goto to Search >> Search Notepad >> Run as Administrator
2. On Notepad window, select File >> Open
3. Navigate to
C:\Windows\System32\drivers\etc and set file types from “Text Document” to “All Files”
4. Open the
hosts file. Remember the file has no extension
5. Add your custom domain, as mentioned in the example below.
Here, localhost.com is the custom domain and it could be anything.
Now if you are not using XAMPP, and doing it for other backend technologies like Node.js, Django, etc. Just add that line in the host file and you are done. Just visit your domain and port, in this case, it is
You are done. Now, mydomain.com will be redirected to the localhost.
However, If you want to add a custom domain alongside “localhost”. Follow the rest of the tutorial.
Add virtual hosts in apache server
- Launch Notepad >> File > Open
- Navigate to
C:\xampp\apache\conf\extra. Make sure you navigate to the correct directory, where you installed XAMPP.
- Add the below line of codes.
## This for the localhost <VirtualHost *:80> DocumentRoot "C:\xampp\htdocs\mydomain" ServerName mydomain.com ServerAlias mydomain.com <Directory "C:\xampp\htdocs\mydomain"> Require all granted </Directory> </VirtualHost> ## This is for the custom domain <VirtualHost *:80> DocumentRoot "C:\xampp\htdocs\mydomain" ServerName mydomain.com ServerAlias mydomain.com <Directory "C:\xampp\htdocs\mydomain"> Require all granted </Directory> </VirtualHost>
Now restart your apache server and test it by visiting your domain custom domain you set up. If you followed the steps carefully, you should not face any errors.
If in case you are facing some error, please write them down below in the comments.