Sei sulla pagina 1di 14

6/20/2016 How to Change ‘localhost’ to a Domain Name | Complete, Concrete, Concise

Articles Comments

Complete, Concrete, Concise
Practical information without the bloat
Search this website...   Go

Home
Privacy

Complete, Concrete, Concise » Web Tools » How to Change ‘localhost’ to a Domain Name

How to Change ‘localhost’ to a Domain Name
September 6th, 2011 | 23 Comments

This tutorial is for XAMPP 1.7.3 running under Windows XP with Service Pack 3. It may be similar for other
version combinations, but no guarantee is made.

Assumes you have installed XAMPP. Instructions can be found here.

UPDATE 17­March­2012:If you are running Windows 7 (and possibly Vista) the default security settings
prevent you from running applications with administrative privileges. This means that you won’t be able to save
changes made to the hosts file.

For instructions on opening the hosts file for reading and writing please see this article.

Installing XAMPP allows you to develop, test, and play around with web server code on your local machine. You
can configure and test out your website locally, instead of live somewhere on the web.

It does have the drawback that to access your website you have to type localhost/my­web­site, where my­web­
site is actually the directory you installed your website in.

You can setup the Apache Server in XAMPP to serve up web pages as though they were actually located on
www.my­web­site.com instead of localhost.

This is a two step process: first, you have to redirect the web site name to your computer; next, you get Apache
to redirect the web site address to your installed directory.

Redirecting the Web Site to Your Computer
When you type a web site name into the URL field (say, www.google.com), your browser sends the name to a
Domain Name Server that looks up the text name (www.google.com, for example) and returns the Internet
Protocol (IP) address for it (74.125.39.104 is returned for www.google.com). Your browser then connects to IP
address 74.125.39.104.

Before your browser queries the Domain Name Server, it first checks a file called hosts on your computer. If the
requested web site name is found, it uses the IP address found in the file.

1) Locate your hosts file. In Windows XP, this file is located in C:\WINDOWS\system32\drivers\etc:

http://www.complete­concrete­concise.com/web­tools/how­to­change­localhost­to­a­domain­name#print 1/14
6/20/2016 How to Change ‘localhost’ to a Domain Name | Complete, Concrete, Concise

NOTE: Different versions of Windows may store the file in a different directory.

2) Open the file with a plain text editor (like Notepad++). Using a word processor, like Word, can mess up the
file when you save it.

It is very likely that the file is empty, except for the default comment and examples (the section in the green box):

3) Add lines containing the domain name(s) and IP address to redirect to. See the section in the red box in the
image above.

Each line must begin with the address 127.0.0.1 (this is the localhost address)

http://www.complete­concrete­concise.com/web­tools/how­to­change­localhost­to­a­domain­name#print 2/14
6/20/2016 How to Change ‘localhost’ to a Domain Name | Complete, Concrete, Concise

After the IP address, type the name of the domain you wish to redirect to this address. You may only enter
1 name per line.

Addresses like my­site.com and www.my­site.com are different and each need a separate line.

Your address does need to be a “valid” top level domain (i.e. .com, .net, .ca, .pl, etc). It just needs to be composed
of letters (a­z), numbers (0­9), hyphens (­ but not as the start or end of a name) and periods (.). In the examples
above, I used .15, .16, and .17 as the top level domain (which are not valid top level domains).

You can redirect existing domains to your machine. If you entered the line: 127.0.0.1 google.com, then every
time you typed google.com into your URL field, your browser would redirect the request to your machine instead
of going to Google’s web site. NOTE: this redirection only happens on your computer – everyone else in the
world will still go to Google’s home page.

You can also redirect (on your computer only) one website to another. For example, suppose you are boycotting
Google, so you decide to redirect google.com to bing.com instead. You would do that by entering Bing’s IP
address in your host file followed by the web site you want to resolve to that IP address: 195.57.152.178
google.com

4) Save the changes.

5) Restart your browser (if it was open when you made the change to your hosts file).

Getting Apache to Serve Your Web Site
These instructions are for XAMPP 1.7.3. Other versions or XAMPP, or different Apache Server installations may
have the files in different locations, or may even have the files named differently.

6) Locate the httpd­vhosts.conf file. For most XAMPP 1.7.3 installs this will be C:\xampp\apache\conf\extra (in
my case, I installed XAMPP on my D­drive, so the folder is D:\xampp\apache\conf\extra):

7) Open the file using a plain text editor (like Notepad++). Using a Word processor, like Word, can mess up the
file when you save:

http://www.complete­concrete­concise.com/web­tools/how­to­change­localhost­to­a­domain­name#print 3/14
6/20/2016 How to Change ‘localhost’ to a Domain Name | Complete, Concrete, Concise

The file will contain some documentation and sample virtual hosts.

8) Add, at the bottom of the file, new virtual hosts for each domain you added in step 3) above.

Each host will have the following form:

<VirtualHost *:80> 
    ServerName www.joomla.16 
    ServerAlias joomla.16 
    DocumentRoot d:/xampp/htdocs/joomla16 
</VirtualHost>

ServerName: following this label, add the name of the domain you added in step 3)

ServerAlias: following this label, you may add as many alternate domains (separated by spaces) as you like that
are supposed to resolve to this virtual host. Remember that www.my­domain.com is different from my­
domain.com, but, typically, you would want them to resolve to the same server.

DocumentRoot: following this label, add the path where your website is located. You can use an absolute path
(as in the example above), or a relative path (but relative paths can be trickier to set up, so I prefer to use an
absolute path).

9) Save the file.

10) Restart the Apache Server to have the change take effect. Do this by clicking on the Stop button on the
XAMPP control panel and then clicking on the Start button. (You could also just reboot the computer, but that is

http://www.complete­concrete­concise.com/web­tools/how­to­change­localhost­to­a­domain­name#print 4/14
6/20/2016 How to Change ‘localhost’ to a Domain Name | Complete, Concrete, Concise

overkill).

You should now be able to type the domain name into your URL field and go directly to your locally hosted web
site:

http://www.complete­concrete­concise.com/web­tools/how­to­change­localhost­to­a­domain­name#print 5/14
6/20/2016 How to Change ‘localhost’ to a Domain Name | Complete, Concrete, Concise

For more information on configuring virtual hosts, you can read the documentation at the Apache Foundation
here.

There is a lot more you can do with virtual hosts (such as adding an IP address).

Budget web hosting providers use virtual hosts to host multiple websites on the same server (and same IP
address).

Please consider sharing this article if you liked it or found it useful.

You may use one of the buttons below or share using your own favourite media.

Please do not republish this article on your website. You may publish a short excerpt and provide a link back to
the original article.

Share this:

 Print  Email  Google  Twitter  Facebook 34  Tumblr  Pinterest 1  Pocket


 Reddit  LinkedIn 1

Like this:

Loading...

http://www.complete­concrete­concise.com/web­tools/how­to­change­localhost­to­a­domain­name#print 6/14
6/20/2016 How to Change ‘localhost’ to a Domain Name | Complete, Concrete, Concise

Related

How to Change the Apache Port in Installing Joomla 1.5 Under XAMPP Installing WordPress Under XAMPP


XAMPP In "Joomla" In "WordPress"
In "Web Tools"

Filed under: Web Tools · Tags: change, domain, domain name, localhost, name, XAMPP

23 Responses to "How to Change ‘localhost’ to a Domain Name"

1.   Bob Brown says:
Oct 20, 2011 at 06:00

Thanks for this post! Useful.

I have a question about the second half of this tutorial regarding the Virtual Hosts in Apache.

It seems whether I set the Virtual Host or not it doesn’t make any difference.

In my hosts file I put,

127.0.0.1 dev.16

In my browser I can access http://dev.16 with or without the virtual hosts setup in httpd­vhosts.conf

Not sure exactly what that does? Can you explain?

Thank you

1.   admin says:
Oct 20, 2011 at 07:47

Thanks for your comment.

I would guess that Joomla! or whatever site you are running on your local host is located in the root
of the htdocs directory. In other words, if you typed in localhost (or 127.0.0.1) into your browser’s
URL field, you would go to your website instead of the XAMPP local host homepage (assuming you
are running XAMPP).

The virtual hosts setup is needed to redirect the URL to the sub­directory hosting your site. For
example, your site might be located in /htdocs/mysite/….

http://www.complete­concrete­concise.com/web­tools/how­to­change­localhost­to­a­domain­name#print 7/14
6/20/2016 How to Change ‘localhost’ to a Domain Name | Complete, Concrete, Concise

Your web server (whether Apache or IIS or something else), serves up web pages from a specified
directory. For XAMPP, this directory is xampp/htdocs, for AMPPS, the directory is /ampps/www, for
IIS it is usually c:\www. Those are the directories the server looks in when you enter localhost (or
127.0.0.1) into your browser’s URL field.

Often times, in that directory is some sort of management console for your server / mysql / php / perl
installation. Web sites are usually installed into subdirectories, this is why you need to type
localhost/mysite instead of just localhost.

I hope that helps clarify things.

1.   kishore says:
Mar 17, 2012 at 02:11

Hi,

Thanks for your valuable document. you explained that the change can done in one pc only.
but i want to do for different systems which means if we give name to the url and enter the
name in any system the url should call from any system.

Is it possible can give the suggesstion.

Thanks in advance

1.   admin says:
Mar 17, 2012 at 03:51

I’ve never tried running Apache over a server, however, you might want to check out the
following sites for additional information:

Can’t start Apache with mapped network drive – the solution seems to be to use UNC
path instead of mapped drive.

Alias network drive Apache Server – the solution is the same as above, use a UNC path

Using Apache over a Local Network – the solution provided here is to edit your hosts
file to map domain names to IP addresses (in this case, the IP address of the Apache
Server.

Accessing XAMPP Over a Network – here they recommend checking that Apache is
listening to port 80, not 127.0.0.1:80. This requires modifying the httpd configuration
files.

Unable to connect Apache over LAN – some good network troubleshooting tips.

I hope these give you something to work with.

1.   kishore says:
Mar 17, 2012 at 05:09

actually i am trying to do url masking for this i m asking the doubt. thanks for
your valuable suggestion.

http://www.complete­concrete­concise.com/web­tools/how­to­change­localhost­to­a­domain­name#print 8/14
6/20/2016 How to Change ‘localhost’ to a Domain Name | Complete, Concrete, Concise

1.   admin says:
Mar 17, 2012 at 10:44

Oops, sorry about that.

Perhaps these pages would be of use:

URL Rewriting

mod_rewrite: A Beginner’s Guide to URL Rewriting Article

2.   kishore says:
Mar 18, 2012 at 22:53

hi,

I have a doubt. Can i give my ip and application included while i change my
domain name e.g: 11.21.34.125:8080/apex like this can i give in the host name?

Please help me in this

Thanks in advance

1.   admin says:
Mar 19, 2012 at 00:37

There is no problem in assigning a URL a domain name.

In the tutorial I map the website addressed by:

localhost/joomla16

to http://www.joomla.16

You have to enter the appropriate information in the httpd­vhosts.conf file.
See the section Getting Apache to Serve Your Web Site (steps 6 to 10).

3.   kishore says:
Mar 19, 2012 at 00:19

Hi,
can we able change the domain name with out tomcat or xampp.

Thanks in advance

1.   admin says:
Mar 19, 2012 at 00:31

I have never used Tomcat so I am not familiar with it. From what I’ve read
about it, Tomcat seems to be a different web server.

You change the domain name using the hosts file on your computer. For
http://www.complete­concrete­concise.com/web­tools/how­to­change­localhost­to­a­domain­name#print 9/14
6/20/2016 How to Change ‘localhost’ to a Domain Name | Complete, Concrete, Concise

example, adding the line:

127.0.0.1 www.google.com

will cause all requests to http://www.google.com to be redirectd to your
localhost server. But this is not enough. You need a localhost server in order
to serve up web pages.

The web server can be Apache, Tomcat, Microsoft IIS or something else.
But you need to configure the web server as well. My instructions are for a
system using Apache server (as bundled with XAMPP – XAMPP is just a
prepackaged collection of Apache Server, MySQL database, PHP, pear, and
some other utilities).

4.   kishore says:
Mar 19, 2012 at 03:36

hi,

Is it possible to give the name to my ip. for using the name can we able to access
my system from another system.

eg:
my ip is 123.21.232.12 for this i wanna give a name like kishore.if i m trying to
access my system application from another system we just mention the ip and port
and application name there instead of ip i wanna use some name. Is it possible?

if possible tell me the answer please.

Thanks in advance

5.   kishore says:
Mar 22, 2012 at 02:08

Hi,
Can give me a answer for my question asked on 19 march

1.   admin says:
Mar 22, 2012 at 05:16

Sorry, I thought my response from March 17 would point you in the right
direction.

You can definitely modify the hosts file on the remote computer so that
when you type in mycoolsite.mine it redirects to the computer serving the
site.

In this case, you would modify the hosts file to point to the networked
computer (you will have to find out the IP address of that computer).

You will also, probably, have to modify the httpd­vhosts.conf on the server
computer.

http://www.complete­concrete­concise.com/web­tools/how­to­change­localhost­to­a­domain­name#print 10/14
6/20/2016 How to Change ‘localhost’ to a Domain Name | Complete, Concrete, Concise

This is about as much as I can help because I don’t have any networked
computers.

2.   Subash says:
Nov 16, 2011 at 04:10

thanks for great tutorial.now i got rid of that localhost.

1.   admin says:
Nov 16, 2011 at 05:51

Awesome! Thanks for the feedback.

3.   tiwa says:
Nov 27, 2011 at 15:53

hi

in step3, I can’t save the changes in Notepad++,

the error: please check whether if this file is oppened in another program

1.   admin says:
Nov 27, 2011 at 22:18

That error message will occur if the file you are editting is locked. The most common reason is that
you have openned the file with another application (for example,Word – which locks files when it
opens them). It is necessary to close any applications that might have the file open.

If worst comes to worse, you may ned to log out and log back in (not just switch user).

UPDATE 17­March­2012: This error will occur on Windows 7 unless you are running the program
with administrator privilege. See this article on how to do that.

4.   Viktor says:
Dec 11, 2011 at 16:42

how about setting it up from apache 2

1.   admin says:
Dec 12, 2011 at 01:36

It should work with Apache 2.x.

The Apache Server found in XAMPP 1.7.3 is 2.2.14
The Apache Server found in XAMPP 1.7.4 is 2.2.17
The Apache Server found in XAMPP 1.7.7 is 2.2.21

If you have installed Apache Server independantly of XAMPP, then some directories may be
different, but the setup should be the same.

http://www.complete­concrete­concise.com/web­tools/how­to­change­localhost­to­a­domain­name#print 11/14
6/20/2016 How to Change ‘localhost’ to a Domain Name | Complete, Concrete, Concise

5.   Lei Raffaelli says:
Jan 10, 2012 at 19:02

This is helpfull,,, thaks a lot, buddy.. :­))

1.   admin says:
Jan 10, 2012 at 22:33

You’re welcome and thanks for the feedback.

6.   arlene says:
Mar 23, 2012 at 00:31

sir please teach me how to configure my database settings in order to connect in the internet.. thanks a
lot…

1.   admin says:
Mar 23, 2012 at 04:14

I’ve never done it but my understanding is this:

(1) you need a static IP address. Your computer (which is acting as your web server) must always be
connected to the Internet at the same address. Most Internet conection plans give you a dynamic IP
address – it changes regularily. You will need to ask your Internet provider for a static IP address.
This will probably cost extra.

(2) you need to point your domain name servers to your IP address. This way, when people type in
mycoolsite.com the name server points them to your computer’s IP address on the Internet (now you
see why you need a static IP address).

(3) you need to ensure that port 80 (http) is open (not blocked by a firewall). If you need to serve
secure pages, then you also need to ensure port 443 (https) is also open. If you also need ftp access,
then you have to ensure that ports 20 (data) and 21 (command) are open.

A quick search reveals that some companies (like this one) claim to allow you to run a site on a
dynamic IP address as though the IP address was static. NOTE: I have no experience with this
company or others offering the same service, so I cannot evaluate how true their claims are).
Proceed at your own risk. From what I can see, they do this by having you prefix your site to a
choice of domains they have (like mycoolsite.no­ip.org, or mycoolsite.servegame.com) andc with a
bit of software magic, they redirect to your server (even if the IP address changes). I presume they
are able to do this because you have to run some software on your server. I presume the software
keeps their server informed of your IP address, so even if your IP address changes, they get updated
about it.

You can see which ports are open on your computer by using GRC’s port scanner. Click on Proceed
then click on All Service Ports.

Subscribe to Site via Email
Enter your email address to subscribe to this site and receive notifications of new posts by email.

http://www.complete­concrete­concise.com/web­tools/how­to­change­localhost­to­a­domain­name#print 12/14
6/20/2016 How to Change ‘localhost’ to a Domain Name | Complete, Concrete, Concise

Email Address
Email Address

Subscribe

Search the Web with Google

  Search

Categories

Blog (33)
Electronics (1)
Joomla (16)
Mathematics (17)
Programming (24)
C (20)
C++ (21)
FLTK (1)
Java (1)
Ubuntu (95)
Ubuntu 11.10 (17)
Ubuntu 12.04 (45)
Ubuntu 12.04 Server (1)
Ubuntu 12.10 (11)
Ubuntu 13.04 (21)
VirtualBox (17)
Web Tools (25)
WordPress (10)
Writing (5)

Recent Comments
admin on Ubuntu 13.04 – How to Completely Uninstall / Remove the Cinnamon Desktop
1111 on Ubuntu 13.04 – How to Completely Uninstall / Remove the Cinnamon Desktop
admin on Ubuntu 12.04 – How to Completely Uninstall/Remove a Package/Software/Program
Bruce Poudrette on Ubuntu 12.04 – How to Completely Uninstall/Remove a Package/Software/Program
admin on Ubuntu 12.04 – Basic Unity Interface / Desktop Tutorial

Related Posts (YARPP)

1. How to Change the Apache Port in XAMPP

Most commented

Creating a MySQL Database using XAMPP
Installing Joomla! 1.7 Under XAMPP
How to Change the Apache Port in XAMPP
Ubuntu 11.10 ­ Replacing the Unity Interface
Installing Joomla! 2.5 Under XAMPP
Ubuntu 11.10 ­ How to get a Command Line, Shell, or Terminal

http://www.complete­concrete­concise.com/web­tools/how­to­change­localhost­to­a­domain­name#print 13/14
6/20/2016 How to Change ‘localhost’ to a Domain Name | Complete, Concrete, Concise

Recent Articles

Fixing Slow Boot in Windows 7
Security Weakness in FaceBook Login
Brother HL­3140CW Laser Printer – a Review
How to Prevent People from Displaying Your Content on Their Web Pages Inside of a Frame
Replacing the Toner Cartridge in a Brother HL­3140CW Printer
WordPress – Can’t Log into your Website

Tag Cloud

change command line complete completely desktop error fix gnome guest additions
11.10 access adsense c++ 

howto how to install installation installing joomla lxde mysql not working preprocessor
remove removing replace replacing review shell sine terminal tutorial ubuntu ubuntu 11.10
ubuntu 12.04 ubuntu 12.10 ubuntu 13.04 understanding uninstall uninstalling
unity virtualbox wordpress XAMPP xfce
© 2016 Complete, Concrete, Concise
Cover WP Theme

http://www.complete­concrete­concise.com/web­tools/how­to­change­localhost­to­a­domain­name#print 14/14

Potrebbero piacerti anche