Main menu
WalkswithMeApacheHow to rename localhost to a domain in xampp

How to rename localhost to a domain in xampp

The sounds like crazy right ? yes it is, rename localhost to a domain in xampp is for some craze. Ok lets check how we can achieve rename localhost to a domain name. The steps are simple and easy only few things for changing your localhost to a domain name.

rename localhost to domain anme

rename localhost to domain name

First you have to open two files in the following directories. The file names are httpd-vhosts.conf in apache  folder and  host in windows folder.

Step 1 :

//The httpd-vhosts.conf file you can find in the following path .The drive here is "C" that will change according to your installation.
C:\xampp\apache\conf\extra\

Open the Above file and add the following codes at the end of the file.You have to edit this file using notepad or notepadd++ not open it in word or any other modern document it may messed up the characters and encoding. Here Iam changing my localhost to “dreamdevelopers.com”


<VirtualHost *:80>
ServerName www.dreamdevelopers.com
ServerAlias dreamdevelopers.com
DocumentRoot c:/xampp/htdocs/
</VirtualHost>

Then save the file and the follow next step

Step 2 :

Now you configure the domain name in apache services then you need to edit the host  file of windows for DNS look up check the following file path and open the file.

 


//The host file you can find in the following path in most Operating system Win7/xp/Vista
C:\WINDOWS\system32\drivers\etc

Open the file and follow the steps. just need to change # from the beginning and add you domain name instead of   follows.


# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost

The above section you have to modify as follows.


# localhost name resolution is handled within DNS itself.
127.0.0.1 dreamdevelopers.com
::1 dreamdevelopers.com

Then save the file and restart your Apache server and mysql. Now see the magic . 🙂

rename localhost to a domain in xampp

rename localhost to a domain in xampp

Did you face any difficulties to stop and start Apache services like error “apache not stop error -1” try this method.


Start
Run
Type services.msc
Find the Apache and mysql services
Right click and stop , or restart

Also you may face issue with permission on host file editing and saving, you can only do this if you are an admin user. If you are admin and still the issue try this.

Copy your existing host file to any other location like d:\ then make edit on it and paste back to same folder 

C:\WINDOWS\system32\drivers\etc
You have take a backup for host file before doing this.

enjoy localhost with any domain name 🙂 🙂 🙂

 

 

 

17 thoughts on “How to rename localhost to a domain in xampp

  1. Hello everyone,

    I have installed Apache/2.4.23 and PHP/7.0.9. Am trying to accessing my localhost through domain name on both LAN and Internet for that I made the changes in following files

    1. hosts file —> added my static ip address of my laptop

    2. httpd-conf —> change the port number 80 to 7070

    3. httpd-xampp.conf —> and given permission “Require all granted”

    through ip 192.168.2.50:7070 over lan I am able to access localhost but not by domain name.

    and moreover how do i access the localhost across the network please help me..

  2. Thanks admin,

    I have used the same method to test our website on local. it helps us to find bugs.

    Once again Thanks.

  3. many thanks for the beautiful post. my question is did this method work from the smartphone to access localhost via domain name.

    1. I think you confused , “services.msc” is not a file to search.
      simply type it on Run window of windows system.
      Windows + R is short key for open up the Run prompt.

      Hope it make sense..

  4. sir my apache is not runnig may i know where exactly should i paste this code?

    Start
    Run
    Type services.msc
    Find the Apache and mysql services
    Right click and stop , or restart

    1. This code is not need to paste, you have to follow the path like
      in windows Windows key + R will open run window.
      just type “services.msc”
      it will open the service manager of windows
      find Apache and mysql services click restart.

      Hope its clear.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

FacebookTwitterGoogle+RSS