Jump to content
xisto Community
xpress

How To Assign A Virtual Domain Name To Your Localhost. Assigning virtual domain names and websites to your localhost.

Recommended Posts

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://forums.xisto.com/no_longer_exists/ instead of 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://forums.xisto.com/no_longer_exists/ 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 Xisto.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://forums.xisto.com/no_longer_exists/. 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 (see edit history)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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	   localhost127.0.1.1	   rob-laptop# The following lines are desirable for IPv6 capable hosts::1	 ip6-localhost ip6-loopbackfe00::0 ip6-localnetff00::0 ip6-mcastprefixff02::1 ip6-allnodesff02::2 ip6-allroutersff02::3 ip6-allhosts

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

Share this post


Link to post
Share on other sites

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 :))

Share this post


Link to post
Share on other sites

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

localhost/mysite, or localhost/mymail. But f you have these virutal domains you can directly call them 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 OpaQue (see edit history)

Share this post


Link to post
Share on other sites

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 tutsaves me typing /localhost/website all the time as i have 7 sites currently

Notice from jlhaslip:
Edit to remove questionable adjective

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

I'm using XAMPP. The first part of the tutorial worked for me but the second part didn't. I changed the path in two places in my httpd.conf file but my new localhost still directs me to the xampp home and I have to tediously sift through subdirectories to get to the directory which I want to be my default. Sorry for the long sentence, I hope it makes sense. Can anyone help me with this?

Share this post


Link to post
Share on other sites

I'm using XAMPP. The first part of the tutorial worked for me but the second part didn't. I changed the path in two places in my httpd.conf file but my new localhost still directs me to the xampp home and I have to tediously sift through subdirectories to get to the directory which I want to be my default. Sorry for the long sentence, I hope it makes sense. Can anyone help me with this?

Its working fine buddy....I just downloaded and installed xampp and made the changes as well....working without any problem.

As I already told just little modifications are needed. The only change need is DocumentRoot....just copy and paste the following code and change your domain and website details as I instructed below...

 

First open the httpd.conf in the C:\xampp\apache\conf folder.

 

Then at the end of the code add the following

 

NameVirtualHost 127.0.0.1<VirtualHost 127.0.0.1>ServerName localhostDocumentRoot "C:/xampp/htdocs"</VirtualHost> <VirtualHost 127.0.0.1>	ServerName mysite						#your virtual domain name created in hosts file	DocumentRoot "C:/mysite"			  #replace "C:/mysite" with location of your website 	<Directory C:/mysite>					#enter location of your site here also...	 		Order Allow,Deny		Allow from all	</Directory></VirtualHost>

After modifications save the file...and don't forget to restart your apache server to see the changes....

Now type http://forums.xisto.com/no_longer_exists/(or the domain you've chosen).....and you should see your website...(another thing...you must have an index page in your website)

 

Thats it. I just checked it in XAMPP..its working. If you are still facing problems..please post the modifications you did to the httpd.conf file.... :)

Share this post


Link to post
Share on other sites

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://forums.xisto.com/no_longer_exists/ instead of 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://forums.xisto.com/no_longer_exists/ 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 Xisto.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://forums.xisto.com/no_longer_exists/. 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.


Hey dude,

Great job as i am using wamp server for the script testing and making i always wanted to call my localhost with a special name...

 

Or in other words i wanted to call it compneedz as it is the name of my website...

 

This trick can also be used to trick your friends by opening your site without the internet connection what do you think??

Share this post


Link to post
Share on other sites

Thankyou for the awesome tutorial, I only did the first part as the second part wasn't useful for me, but great job... On this topic, is there a way you can move the testing server folder so you can put files in without having to give it "Admin" control?

Share this post


Link to post
Share on other sites

Thankyou for the awesome tutorial, I only did the first part as the second part wasn't useful for me, but great job...

Well, the second part is the real interesting one :P With the help of second part, you can use different folders for different websites (local) and you can access each of them with seperate domain name.

On this topic, is there a way you can move the testing server folder so you can put files in without having to give it "Admin" control?

I didn't understand your question. Could you post it clearly? Do you mean you want to put your website folder somewhere else other than the default one( for example the default website folder for WAMP is "www") ? If so, its possible. And you can find it in the second part of the tutorial.. If not, please post your problem clearly... :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.