JLBN

Free WAMP Guides & Website Design Templates
header image

JLBN – Setup Virtual Hosts on WAMP

July 30, 2008 By: BN Category: WAMP Comments (44)

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

[Read more...]

Share & Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Blogplay
  • HackerNews
  • LinkedIn
  • Live
  • NewsVine
  • Reddit
  • StumbleUpon
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Yahoo! Buzz
  • email
  • MisterWong
  • MySpace
  • RSS
  • Tumblr
  • BlinkList
  • Design Float
  • FriendFeed
  • Mixx
  • Netvibes

44 Comments to “JLBN – Setup Virtual Hosts on WAMP”


  1. 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

    1
    • 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

      2
  2. 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>

    3
    • 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>

      4
  3. 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

    5
  4. where is that existence of these scripts is to manually turn please help

    6
  5. 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

    8
  6. Mike Moore says:

    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.

    10
    • 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

      11
  7. 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

    12
  8. 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.

    13
    • Derek, make sure to setup that http://myfriendsite on the top in VH ;)

      14
  9. 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

    15
    • 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

      16
  10. 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

    17
  11. Kurashige says:

    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.

    18
  12. 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

    19
    • flanzer, theory you can do it but you have any reason to do so?

      20
  13. SKEEN thans

    21


Leave a Reply