JLBN – Setup Virtual Hosts on WAMP
There are too many ways to setup Virtual Hosts for both local and global access, so here, in this setup Virtual Hosts guide for WAMP, we only show the most basic method to get you going 😉
In this setup Virtual Hosts guide for WAMP, we will desmontrate to setup 1 localhost, 1 local domain (domain), 2 local subdomains (sub1 and sub2), 1 domain (domain.com), and 2 subdomains (sub1.domain.com and sub2.domain.com)
Even you don’t have real domain, you can still follow this guide to the section for setting up Virtual Host without domain 😉
Note: Even this guide is used for Wampserver, you can apply this method on other wamp package such as Xampp, EasyPHP, so on. Just make sure to select correct file(s) in proper location(s) 😉
hi JL,
thanks for reply
but it does:
`<VirtualHost 192.168.16.3:85>
ServerName intranet
DocumentRoot “D:/wamp/www/snapper”
ErrorLog “D:/wamp/www/snapper/logs/error.log”
</VirtualHost>
#convert.intranet
<VirtualHost 192.168.16.3:85>
ServerName convert.intranet
DocumentRoot “D:/wamp/www/convert”
ErrorLog “D:/wamp/www/convert/logs/error.log”
</VirtualHost>`
your form must have “eatten” when i posted
Elen, correct your hosts file as follows:
192.168.16.3 convert.intranet
Then in browser, use this URL “http://convert.intranet”
You might have to restart Wamp or your computer to take effect
Hi! thank you for putting up such brillian tutorials.
however i can’t get it working, but i guess my problem is bit more complicated…
here are my config files:
——
httpd.conf
——
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
——
httpd-vhosts.conf
——
NameVirtualHost *:85
ServerName intranet
DocumentRoot “D:/wamp/www/snap”
ErrorLog “D:/wamp/www/snapper/logs/error.log”
#convert.intranet
ServerName convert.intranet
DocumentRoot “D:/wamp/www/convert”
ErrorLog “D:/wamp/www/convert/logs/error.log”
——
hosts (in Windows/system32/… folder)
——
192.168.16.3 intranet
192.168.16.3 convert
——————-
so i have 2 abnormality:
1. i need to use specific IP (as we have server and few PCs)
2. it has to be on port 85 (as localhost already taken by MS web server, but not in use)
with the settings above i get website in folder snap/ working when i call http://intranet:85 in browser – which is expected behaviour.
But http://convert.intranet:85 – 404 page could not be found error
what am i doing wrong?
Elen, your hosts file does not reflect the local domain you setup in VH so you need to correct either one to match the other
hi, first thank you for your useful information. when i was access host computer from another computer on the net i receive this error
Forbidden
You don’t have permission to access / on this server.
Apache/2.2.21 (Win32) PHP/5.3.9 Server at 173.244.172.165 Port 80
can you help me about this error ?!!
omid, no matter within or outside LAN access, you need to setup Access, DNS, and VH; Access for permission to connect to your Wamp PC, DNS to tie Domain(s) to your Wamp PC, and VH to host multiple Domains/Websites/IP’s and even you have only 1 Domain/IP, you should use VH to set it up w/ the site you want to show up first on top and localhost on bottom and others in middle if having more than 1 site; w/ VH, other PC’s, no matter w/i or outside LAN, can access/see websites/contents of that particular folder set for that particular VH on your wamp PC. If dont have real Domain, just skip DNS guide
To setup Access, follow this
http://blog.jlbn.net/?p=21
To setup VH, follow this
http://blog.jlbn.net/?p=23
To setup DNS, follow this
http://blog.jlbn.net/?p=28
TNX BN, it is very important for me 🙂
If it helps anyone here I have a tutorial on setting up virtual hosts and subdomains on Wamp here: http://www.itutorblog.com/2011/06/how-to-create-a-subdomain-on-wamp/
Thanks for the information which was really useful, I was looking for it and I will be waiting for your next post.
Ok guys,
I’ve done my dns, virtual host files, backup, and my http site is working fine. However, when trying to setup ssl, I’ve run into some issues. I’ve followed your settup for ssl all the way through. I can only connect and see the test page under localhost, and it gives me a warning that my certificate is for a different website address which I expected, since it’s registered to http://www.my_domain>net. When I try to connect thru my website address, Internet Explorer won’t display the test page.
From my standpoint, it’s logical that, since I can view the ssl test page thru localhost, my configuration is pretty close to what I need. I suspect that the ssl VirtualHost file needs to change to point to the actual site, but I’ve tried several variations with no luck.
Currently, my VirtualHost file in httpd-vhosts.conf points to;
Name VirtualHost xxx.xxx.x.x:80
<VirtualHost xxx.xxx.x.x:80
ServerName http://www.my_domain.net
DocumentRoot "C:/wamp/www/my_site_filename
ServerAdmin admin@my_domain.net
Alias /my_site_filename/ "c:/wamp/www/my_site_filename/"
AllowOverride None
Order allow,deny
Allow from all
ErrorLog “c:/wamp/www/my_site_filename/logs/sei_error.log”
CustomLog “c:/wamp/www/my_site_filename/logs/sei_access.log” common
which, as I said, works fine.
My VirtualHost file in httpd-ssl.conf is configured as;
# General setup for the virtual host
DocumentRoot “C:/wamp/www/my_site_filename/ssl”
ServerName http://www.my_domain.net:443
ServerAdmin admin@my_domain.net
ErrorLog “C:/wamp/bin/apache/Apache2.2.11/conf/ssl/logs/ssl_error.log”
TransferLog “C:/wamp/bin/apache/Apache2.2.11/conf/ssl/logs/ssl_access.log”
which I can only access from localhost, not from http://www.my_domain.net.
Tell me, where have I gone wrong. In the initial VirtualHost definition, I’ve tried xxx.xxx.x.x:443, http://www.my_domain.net:443, my_domain.net:443, and my_site_filename:443 instead of _default_:443, with no response.
I’m missing something somewhere. Help!….
Tom,
Did you follow our Setup Access guide to setup port forward for port 443?
Also, you have couple mistakes there:
Name VirtualHost *:80
<VirtualHost *:80>
ServerName www.my_domain.net
instead
Name VirtualHost xxx.xxx.x.x:80
<VirtualHost xxx.xxx.x.x:80>
ServerName http://www.my_domain.net
Also
ServerName www.my_domain.net:443
instead
ServerName http://www.my_domain.net:443
SKEEN thans
Is it ever possible to use multiple virtual host for one document root . sorry if this sound stupid but what i want is to create multiple virtual host for one document root.
if my Doc root is at c://wamp/www/mysite is there any way i can access it as http://localhost:82 and http://localhost:85 together ?
please help
flanzer, theory you can do it but you have any reason to do so?
how will I add the virtual host of an ASP (aspx) website and not the usual PHP (index.htm and index.php)? I already configured the aspx on my wamp and on my localhost, I can see the asp.net website. How to make it accessible to the internet? I get the error Internal server Error when I point the DirectoryIndex to Default.aspx of my website. But through localhost/aspx I can see the website clearly and without error.
Thanks, JL. I believe I understand better. Regarding the possible confusion, let me explain what I am trying to do:
I already have a wordpress site set up at C:\wamp\www\wordpress using your instructions for database and wordpress.
I plan to use this as a template for my registered domains and use your new instructions for moving wordpress to move it to each of my domains locally (C:\wamp\www\mysite.com) etc. and after configuring, load to the production server online.
I want to build them locally using the full domain name to reduce the amount of editing needed before uploading to the prodution server. (see my post above from May 30, 2010) And also to be able to see them locally as close as possible to how they will actually look and work online.
I currently have vh working using my full domain names (http://mysite.com). WOHOO you guys ROCK!
You are saying these are now accessible from outside my LAN/machine that WAMP is on at that address. So I should run WAMP in offline mode. (also accomplished by not starting WAMP if I am not using it, correct?)
And to avoid confusion of whether I am viewing local or production server, if I want to view the production server I could comment out the line with a “#” in my hosts file for that domain, right? (could also load a simple text file to the production server only, and remember to enter that url to see I am viewing the production server, but not what I want to do)
I have a couple of suggestions for these vh instructions: I had some confusion if I needed an entry for my wordpress install in vhosts.conf, you might want to add it is not needed.
Second, my localhost (C:/wamp/www) did not have a logs folder and WAMP would not work until I added it. Your instructions only read to add a logs folder for each site.
Thanks again
-JEDs
Regarding something Derek stated above: “If you used, for example, site1.com for the local virtual host, you would never be able to actually reach the live site. All requests for the live site would be re-directed to your local virtual host.”
I can understand this, however it wouldn’t hold true if WAMP was not active, correct? WAMP does not start on my machine until I start it, and localhost is not available until I start it, therefore I could browse to the production server and not the local of the same name if I had not started WAMP.
In my case I am only using WAMP to test the install, I have no interest in even being able to browse localhost from the LAN, only from the machine WAMP is installed to.. But I want to use the same domain name locally for testing.
-JEDs
Steve, if you just simply want to run your site on your Wamp PC only, not even within LAN, then you should just name your site “site1” instead trouble yourself with the name “site1.com” which duplicates the real live domain and it would confuse you sometimes since you might not sure if you’re looking at the real site or the local site; also, through Wamp tray icon, set your Wamp in off-line mode so no outsider can access your site either 🙂
To make it more clear, here is the example: if you setup VirtualHosts with local domain msn.com, even you don’t turn on Wamp, you still see the website msn.com as long as your Internet connection alive since this is the real site from Microsoft; however, if you modify the hosts file, you might get the error more than actually see the local site; therefore, you should avoid to name your local domain that contains http://www., .com, .net, … so on
I think I understand now – from another site:
In reality, you can call the domains anything you want. You could just as easily name them microsoft.monkeybutt and ibm.greentambourine. I choose to use the convention of using the same domain name along with the .local TLD to simplify and minimize the typing needed to switch between the live site and the testing site. The only important point, and it’s really important, is that you NEVER use an actual, real, live domain name. If you used, for example, site1.com for the local virtual host, you would never be able to actually reach the live site. All requests for the live site would be re-directed to your local virtual host.
—————————-
So I can just set virtual host to http://myfriendsite and he can access by typing my we ip into his browser to see the changes.
Thanks so much.
Derek, make sure to setup that http://myfriendsite on the top in VH 😉
I Just landed here a couple of hours ago and this is the best resorce I’ve found after searching 2 days. After reading everything twice I still cannot get my head around this:
I am setting up a new wordpress site for my friend to replace his existing static site. Let’s say his site is hosted at http://myfriendsite.com – Can I set up virtual host on my computer with the actual domain http://myfriendsite.com so I can develop it with the full paths for urls and show him updates of the work i’ve done?
To view it from his computer he would have to access it by typing my ip in his browser and it will show as http://myfriendsite.com
You said about using microsft.com locally but you said use microsoft without the .com on the end?
This will also make it easier to upload to his server when it’s time to go live.
Sorry if this sounds so noobish but I just can’t get it to click in my brainbox.
Thank you for any help.
Dererk
How can i Allow web access to my myql wamp server database, I set up wamp to use as a mysql server.
I dont have a domain setup on the wamp server, only for mysql.
I need to know how to set up direct web access to mysql database and what url format to use.
I followed instuctions under virtual host setup, but it fails to resolve host when trying to connect from the web.
I do not want to allow access from an anonymos public connection,only from one web site or IP address.
Mike Moore, it’s NOT recommend to have direct MySQL access since hackers, spammers and even some want-to-be hackers and spammers might get into your MySQL server and it’s very dangerous if your databases contain sensitive information 🙁
If you still insist, you still face another problem because you dont have a domain unless you have a static IP if you want to use your IP for setup
Anyway, you need to setup Access, DNS, and VH; Access for permission(s) to connect to your WAMP PC, DNS to tie domain(s) to your WAMP PC, and VH to host multiple domains/IP/websites and even you have only 1 domain/IP/website, you should use VH to set it up with the site you want to show up first on top and localhost on bottom while other domains/IP/websites in middle if having more than 1 domain/IP/website; if dont have real domain, just skip DNS guide
To setup Access, follow this
http://blog.jlbn.net/?p=21
To setup VH, follow this
http://blog.jlbn.net/?p=23
To setup DNS, follow this
http://blog.jlbn.net/?p=28
wouldn’t this be useful for moving your site from localhost to an online server?
Then you wouldn’t have to edit files to change instances of http://localhost/yoursite with http://www.yoursite.com, you would be all set to import the db and upload files??
Or am I way off base?
Thanks,
JEDs
Steve, with VH you can setup http://www.yoursite.com as demonstrated here
where is that existence of these scripts is to manually turn please help
david, not very quite sure about question, so you might post your purpose instead 😉
Thank you… I had a simple mistake here and was looking in the directory paths to find the answer.
NameVirtualHost *80
rather than
NameVirtualHost *:80
here is the converted code from above
<VirtualHost *:80>
ServerName coalcanyon
DocumentRoot c:/coalcanyon
ErrorLog c:/coalcanyon/logs/coal_error.log
CustomLog c:/coalcanyon/logs/coal_access.log common
<directory c:/coalcanyon>
Options Indexes FollowSymLinks
AllowOverride All
Order Allow,Deny
Allow from 127.0.0.1
</directory>
</VirtualHost>
<VirtualHost *:80>
ServerName johntrot
DocumentRoot C:/johntrot
ErrorLog c:/johntrot/logs/trot_error.log
CustomLog c:/johntrot/logs/trot_access.log common
<Directory C:/johntrot>
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName johdi
ServerAlias jondi
DocumentRoot c:/wamp/www/jondi
ErrorLog c:/wamp/www/jondi/logs/error.log
CustomLog c:/wamp/www/jondi/logs/access.log common
</VirtualHost>
<VirtualHost *:80>
ServerName babs
ServerAlias babs
DocumentRoot c:/wamp/www/babs
ErrorLog c:/wamp/www/babs/logs/error.log
CustomLog c:/wamp/www/babs/logs/access.log common
</VirtualHost>
<VirtualHost *:80>
ServerName localhost
DocumentRoot C:/wamp/www
ErrorLog C:/wamp/www/logs/error.log
CustomLog C:/wamp/www/logs/access.log common
</VirtualHost>
john, did you put NameVirtualHost in the first line? Also, make sure it’s case sensitive
NameVirtualHost *:80
<VirtualHost *:80>
ServerName coalcanyon
DocumentRoot C:/wamp/www/coalcanyon
ErrorLog "C:/wamp/www/coalcanyon/logs/coal_error.log"
CustomLog "C:/wamp/www/coalcanyon/logs/coal_access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerName johntrot
DocumentRoot C:/wamp/www/johntrot
ErrorLog "C:/wamp/www/johntrot/logs/trot_error.log"
CustomLog "C:/wamp/www/johntrot/logs/trot_access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerName johdi
DocumentRoot c:/wamp/www/johdi
ErrorLog "C:/wamp/www/johdi/logs/error.log"
CustomLog "C:/wamp/www/johdi/logs/access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerName babs
DocumentRoot c:/wamp/www/babs
ErrorLog "C:/wamp/www/babs/logs/error.log"
CustomLog "C:/wamp/www/babs/logs/access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerName localhost
DocumentRoot C:/wamp/www
ErrorLog "C:/wamp/www/logs/error.log"
CustomLog "C:/wamp/www/logs/access.log" common
</VirtualHost>
With the following edited files on wamp 2.oi I only get the first listed in the “httpd-vhost.conf” file to work at a time.
When I change the order in the file the new top virtualhost will work, but not the others
typing in my brouser:
http://coalcanyon/
http://johntrot/
http://jondi/
http://babs/
How do I get them all to work without changing the listing order?
“hosts” file
###########################
127.0.0.1 localhost
127.0.0.1 coalcanyon
127.0.0.1 jondi
127.0.0.1 babs
127.0.0.1 johntrot
“httpd-vhost.conf” file
###########################
ServerName coalcanyon
DocumentRoot c:/coalcanyon
ErrorLog c:/coalcanyon/logs/coal_error.log
CustomLog c:/coalcanyon/logs/coal_access.log common
Options Indexes FollowSymLinks
AllowOverride All
Order Allow,Deny
Allow from 127.0.0.1
ServerName johntrot
DocumentRoot C:/johntrot
ErrorLog c:/johntrot/logs/trot_error.log
CustomLog c:/johntrot/logs/trot_access.log common
Order Allow,Deny
Allow from all
ServerName johdi
ServerAlias jondi
DocumentRoot c:/wamp/www/jondi
ErrorLog c:/wamp/www/jondi/logs/error.log
CustomLog c:/wamp/www/jondi/logs/access.log common
ServerName babs
ServerAlias babs
DocumentRoot c:/wamp/www/babs
ErrorLog c:/wamp/www/babs/logs/error.log
CustomLog c:/wamp/www/babs/logs/access.log common
ServerName localhost
DocumentRoot C:/wamp/www
ErrorLog C:/wamp/www/logs/error.log
CustomLog C:/wamp/www/logs/access.log common
john, you code is missing some lines, so suggest to use our online tool here to convert them before posting, so we can can read in order to help you out
Online HTML Conversion Tool