|
|
How To Assign A Virtual Domain Name To Your Localhost. - Assigning virtual domain names and websites to your localhost. | ||
Discussion by xpress with 34 Replies.
Last Update: February 13, 2012, 10:28 am ( View Rated (4) ) (View Latest) | Page 1 of 2 pages. | ||
![]() |
|
|
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.
CODE
127.0.0.1 localhostIn the next line add your virtual domain name like the example shown below.
CODE
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.
CODE
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.
CODE
<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.
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.
QUOTE (rvalkass)
This can be applied to Linux users too actuallyThe 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.
Link: view Post: 421997
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.
What about adding virtual domain names in Linux like adding it to hosts file in Windows(redirecting the localhost)? Do you have any idea?
QUOTE (xpress)
What about adding virtual domain names in Linux like adding it to hosts file in Windows(redirecting the localhost)? Do you have any idea?Link: view Post: 422000
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:
CODE
127.0.0.1 localhost127.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.
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
QUOTE (Lightning73)
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
Link: view Post: 422017
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.
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
QUOTE (websey)
Cheers express, You always bring a good tut, Also just one thing I use xampp is there much difference ????Link: view Post: 422044
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.
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.
QUOTE (asdftheking)
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?Link: view Post: 422465
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
CODE
NameVirtualHost 127.0.0.1<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "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://mysite(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....
QUOTE (xpress)
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.
CODE
127.0.0.1 localhostIn the next line add your virtual domain name like the example shown below.
CODE
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.
CODE
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.
CODE
<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.
Link: view Post: 421938
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??
QUOTE (triplebtalk)
Thankyou for the awesome tutorial, I only did the first part as the second part wasn't useful for me, but great job...Link: view Post: 427619
Well, the second part is the real interesting one
QUOTE
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...
QUOTE (triplebtalk)
Yeah, that is exactly what I meant but I am using EasyPHP and I can't find the file you specify. I am using Vista and I need to give it Admin control to be able to put a file in the testing servers folder. What would the variation be for EasyPHP or should it be the same?Link: view Post: 427679
Sorry yaar, I don't have Vista to test EasyPHP on it. But I will download EasyPHP and try it on my XP system and post the result here. In the mean time try to find httpd.conf file and change it as per the second part. Anc check whether it is working or not...
I was wondering if you could do this is IIS, there is a host file in system32, but if I edit that, it only works for the edited host file.
eg
computer 1 with edited host file
<external ip> www.Website.Com - links to localhost, but external ip.
computer 2 - non edited host file
www.Website.Com - doesnt work, because host file isnt edited.
hope you get my drift of what I'm trying to acheive.
thanks
-reply by robertKeywords: how to create a domain name that links back to localhost
I have run through your very well written process. Doing so crashes apache.
I am using xampp 1.7 on ubuntu hardy 8.1
The only difference is that httpd.Conf in my version has a "include httpd-vhosts.Conf file line.
If I put the virtual name code there I get 403 code forbidden. Does not matter if I change or block permissions.
Is there somewhere else on httpd.Conf that I can change permissions. The only line I see is already set for all.
Just learning so if it is obvious please be kind. :)
-reply by Todd
Just a reply on who commented that it's not very useful, I'm masking my files in the URL, so I need to have a virtual domain for something like "http://someSite/Home" to work
http://localhost/someSite/Home won't work.
-reply by Astral Axiom
QUOTE (xpress)
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.
CODE
127.0.0.1 localhostIn the next line add your virtual domain name like the example shown below.
CODE
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.
CODE
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.
CODE
<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.
Link: view Post: 421938
Thanks for this nice sharing can you plz also teach how to use SMTP service??
Thanks,
I was searching for this today so others might find it helpful too... If you also want to also have www.Mysite.Web you can use ServerAlias, just under 'ServerName' like this:
<VirtualHost 127.0.0.1> ServerName mywebsite.Web #change this virtual domain name ServerAlias *.Mywebsite.Web #change this virtual domain name
That way, you can type http://mysite.Web or http://www.Mysite.Web or indeed http://anythingwhatsoever.Mysite.Web and still be able to see your site.
By the way, instead of .Web, I like to use .Loc to signify that it's a local copy.
-Ian
I'm using Ubuntu 9.04 and I'm running LAMP server. I installed it through my terminal and I didn't have to configure anything. But the problem is when I see my httpd.Conf file which locate /etc/apache2/ there is nothing.
cat /etc/apache2/httpd.Conf
But my localhost running perfectly okey and I'm running some websites also in there. The strange thing is I can't find any other httpd.Conf file in my hard drive.
find / -name httpd.Conf
I'm totally confused. Have someone got any idea.
-reply by anuja
I am following all the steps
I am changing the localhost to mysite into the hosts file.Still I am not gettting the webserver page
I am using windows 7 ultimate
is there any problem
-reply by vivek
in front of the 127.0.0.1 ip i wrote abc.com
and in address bar i keyedin http://abc.com
the page is not egtting displayed
xpress nice tut dude
I have done both part on xampp and wamp having same problem with both software that I can access http://mysite but if I edit httpd.Conf and put that xml codes then apache will not start on both software (I checked one by one) then I edit httpd.Conf again I remove xml codes then apache runs on both software. So can u Please help me on that I don't know y its happen although I reinstall both software again and again.
thnx and advance
take care
-reply by Areenshah
Very useful information!
Thanks!
-reply by Tom Carnevale
Hi,
This article is very useful. I create virtual hosts with a slightly different method. Find the article here:
http://blog.Smriyaz.Com/how-to-create-virtual-hosts-in-windows-wamp-server/
Thanks.Riyaz
-reply by Riyaz Shihabdeen
Similar Topics:
How to assign the Permanent Hardisk...
Assigning A Virtual Name To The Url
Assign Values To Multidimintional A...
Loading...
HOME 





MCITP 70-640: Installing Active Directory on Server Core
Lab 2b - Fedora 15 networking on VirtualBox 4.0.8
Zero Configuration networking with Bonjour
My SQL Community Meeting at Google
TeamSpeak 3 Server Setup With Port Forwarding [Tutorial]
Web Applications and the Ubiquitous Web
Creating Custom Maps with John Coryat
How To Bypass A Router (Port Forwarding)
Changing a SUSE Linux IP Address using YAST

