Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

How To Assign A Virtual Domain Name To Your Localhost.


34 replies to this topic

#1 xpress

    XPRESSing the XPRESSion

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 709 posts
  • Gender:Male
  • Location:X Universe
  • Interests:Computer Security
    Java and PHP
    Music
  • myCENT:93.53
  • Spam Patrol

Posted 07 December 2008 - 01:24 AM

How to assign a virtual domain name to your localhost.



With the help of this tutorial you can assign a virtual domain name to your localhost. That is you can access your local website with your favourite name like http://mysite.web instead of http://localhost and also you can assign different virtual domain names to different local webistes.


Requirements:
1.This tutorial is for Windows. Linux users can also use this, please follow rvalkass's instructions.

2.Apache webserver installed. It would be nice if you have WAMP server. This tutorial is based on WAMP server. But it works on any Apache server with little changes.

Procedure:

part1:

1. First go to location "C:\WINDOWS\system32\drivers\etc" directory.(or where you installed windows). Then open "hosts" file with simple text editor like notepad.

2. You'll see the following code at the end of the file.
127.0.0.1	  localhost

In the next line add your virtual domain name like the example shown below.
127.0.0.1	   mysite.web			  #this is virtual domain name.

3. Now save the hosts file. mysite.web is just an example. You can add anything like "mywebsite.local" and you can use any extension or no extension at all. You can simply add "mysite" also

4. Now test your virtual domain. Just type http://mysite.web You must see your wamp page or webservers defalut page. If not you did something wrong. Go through the tutorial carefully.

Note: Don't use any real domain name like trap17.com or your own domain name if you have any. If you did so, you cannot access the original remote site. This is because, 127.0.0.1 is loopback address, anything with that address will never leave your computer.

Part 2:
Now second part, assigning virtual domain name to your web site in your webserver.

1. Open your httpd.conf file with Notepad. Click on WAMP icon in the tray, go to Apache menu and select httpd.conf there. You can also open the file by manually go to conf folder in Apache folder.

2. Create a new folder mysite in your C directory. And create a new web page index.html. These are for testing purposes. If you have a local website, specify the full path of website in below code.

3. Now add the following code at the end of the httpd.conf file.
NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
	   ServerName localhost
	   DocumentRoot "C:/wamp/www"			#this is default wamp root for websites
</VirtualHost>

<VirtualHost 127.0.0.1>
	ServerName mysite.web			#your virtual domain name
	DocumentRoot "C:/mysite"		#location of your site, no extenison needed
#the following are security settings, allow you to access directory outside the www directory
			   <Directory C:/mysite>			#again location of your website
 		  Order Allow,Deny
		  Allow from all
			   </Directory>
</VirtualHost>
Save httpd.conf file. Restart your WAMP server. now type http://mysite.web. You'll see the index page of mysite.

Adding Another Virtual Domain and Website:

If you want another website, first add another virtual domain in hosts file as shown in part1.
And then copy and paste the following code at the end of httpd.conf file. Just change the virtual domain name, and locations of website.

<VirtualHost 127.0.0.1>
	ServerName mywebsite.web			#change this virtual domain name
	DocumentRoot "C:/mywebsite"			#location of your site, change this.
	   <Directory C:/mywebsite>			#again location of your website, change this
				  Order Allow,Deny
				  Allow from all
	   </Directory>
</VirtualHost>
You can add as many websites as you wish. Just repeat the above procedure.

IF you have any doubts about this tutorial, post them here.

Edited by xpress, 08 December 2008 - 12:35 AM.


#2 rvalkass

    apt-get moo

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 3,107 posts
  • Gender:Male
  • Location:Devon, England
  • Interests:At the moment, Physics mainly!
  • myCENT:69.42
  • Spam Patrol

Posted 07 December 2008 - 10:50 AM

This can be applied to Linux users too actually :)

The hosts file is located at /etc/hosts. The httpd.conf file varies between different distributions, but is often stored at /etc/apache2/httpd.conf. Other than those two changes, the tutorial can be followed in exactly the same way.

#3 xpress

    XPRESSing the XPRESSion

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 709 posts
  • Gender:Male
  • Location:X Universe
  • Interests:Computer Security
    Java and PHP
    Music
  • myCENT:93.53
  • Spam Patrol

Posted 07 December 2008 - 11:03 AM

View Postrvalkass, on Dec 7 2008, 04:20 PM, said:

This can be applied to Linux users too actually :)

The hosts file is located at /etc/hosts. The httpd.conf file varies between different distributions, but is often stored at /etc/apache2/httpd.conf. Other than those two changes, the tutorial can be followed in exactly the same way.
Thanks for the information. I don't use linux that much, so I've no idea about server configurations in Linux. :)
So...now Linux users can also use this tutorial as well. :D

What about adding virtual domain names in Linux like adding it to hosts file in Windows(redirecting the localhost)? Do you have any idea?

#4 rvalkass

    apt-get moo

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 3,107 posts
  • Gender:Male
  • Location:Devon, England
  • Interests:At the moment, Physics mainly!
  • myCENT:69.42
  • Spam Patrol

Posted 07 December 2008 - 11:08 AM

View Postxpress, on Dec 7 2008, 11:03 AM, said:

What about adding virtual domain names in Linux like adding it to hosts file in Windows(redirecting the localhost)? Do you have any idea?

The hosts file on Linux works in exactly the same way as the hosts file on Windows, so I see no reason why you couldn't. For example, this is what mine looks like:

127.0.0.1	   localhost
127.0.1.1	   rob-laptop

# The following lines are desirable for IPv6 capable hosts
::1	 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

As far as I know it is exactly the same as a Windows one, and works in the same way.

#5 Lightning73

    Premium Member

  • Kontributors
  • PipPipPipPipPipPipPipPip
  • 176 posts

Posted 07 December 2008 - 01:34 PM

Looks nice, I looked for this when I just started developing web applications. But now I don't really see the use of this. As you're the only one who'll be able to use the virtual domain name. I just accepted localhost as the domain to use, and it's easy enough.

Correct me if I'm wrong, but even though this tutorial is great, the use of virtual domain names on localhost is useless. (I really hope I'm wrong, so I'll learn something :))

#6 xpress

    XPRESSing the XPRESSion

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 709 posts
  • Gender:Male
  • Location:X Universe
  • Interests:Computer Security
    Java and PHP
    Music
  • myCENT:93.53
  • Spam Patrol

Posted 07 December 2008 - 01:59 PM

View PostLightning73, on Dec 7 2008, 07:04 PM, said:

Looks nice, I looked for this when I just started developing web applications. But now I don't really see the use of this. As you're the only one who'll be able to use the virtual domain name. I just accepted localhost as the domain to use, and it's easy enough.

Correct me if I'm wrong, but even though this tutorial is great, the use of virtual domain names on localhost is useless. (I really hope I'm wrong, so I'll learn something :))

Even though you don't get any great benefits with virtual domain name for localhost, they are quite handy when you have multiple websites on your localhost.

For example you have two webistes in your computer, one is your general site, lets call it mysite, and you're developing another website for mail applications mymail. When you want to access these sites you have to type
http://localhost/mysite, or http://localhost/mymail. But f you have these virutal domains you can directly call them http://mysite or like that. So....it is easy to access your site and also looks informative as well.

And also if you assign a good extension to them they'll look like real domain names. So you can feel them as a real domain name for local websites. :)

Edited by xpress, 07 December 2008 - 02:02 PM.


#7 websey

    Member [Level 1]

  • Kontributors
  • PipPipPipPip
  • 65 posts

Posted 07 December 2008 - 05:18 PM

Cheers express,

You always bring a good tut,

Also just one thing I use xampp is there much difference ????

Also juts one more thing how long does it take to get a *edit by jlhaslip* tut ok'd mine is taking forever and a day !

anyway nice tut

saves me typing /localhost/website all the time as i have 7 sites currently

Notice from jlhaslip:
Edit to remove questionable adjective


#8 xpress

    XPRESSing the XPRESSion

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 709 posts
  • Gender:Male
  • Location:X Universe
  • Interests:Computer Security
    Java and PHP
    Music
  • myCENT:93.53
  • Spam Patrol

Posted 08 December 2008 - 12:46 AM

View Postwebsey, on Dec 7 2008, 10:48 PM, said:

Cheers express, You always bring a good tut, Also just one thing I use xampp is there much difference ????
Thanks websey...Not much difference there with XAMPP, the procedure is same, just locate your httpd.conf file and edit it as per instructions, thats it.

#9 enhu

    Newbie [Level 3]

  • Kontributors
  • PipPipPip
  • 48 posts
  • Gender:Male
  • myCENT:40.06

Posted 08 December 2008 - 04:29 AM

this really helps especially to me since i'm not good in typing. I named my site "mysite" very handy.

#10 freeflashclocks

    Advanced Member

  • Kontributors
  • PipPipPipPipPipPipPip
  • 131 posts
  • Interests:My Girl, Movies, Books, My website about Flash Clocks
  • myCENT:94.81

Posted 09 December 2008 - 05:36 PM

Usefull and very complete tutorial, i also found it simple and easy to read as well as to understand its content and purpose of the same.

I actually never wanted to do this, so i also did not wanted to learn how to do this too, but if i wanted, this would be the tutorial i would choosen to learn, so if in a near future i feel the need to do this steps, this is the best tutorial to have, thank you for your effors, it must have take you quite a while to build it.




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users