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

[Read more…]

72 thoughts on “JLBN – Setup Virtual Hosts on WAMP

  • January 17, 2010 at 11:19 am
    Permalink

    I have been following theis setup but when i try to edit the hosts file in step 5 with notepad i get the following error?

    Cannot create the C:\Windows\System32\drivers\etc\hosts file.

    Make sure the path and file name are correct.

    Can anyone tell me what i am doing wrong?

  • December 24, 2009 at 5:05 pm
    Permalink

    oh it seems WAMP doesnt want to read anywhere from it’s installation path (due to security settings)

    • December 27, 2009 at 8:00 pm
      Permalink

      maxwell, as your error pointed out, you need to setup permission for any location outside your default document root wamp/www folder; for example

      NameVirtualHost *:80

      <VirtualHost *:80>
      ServerName kmr.ru
      DocumentRoot D:/APPSERV/kmr
      ErrorLog "D:/APPSERV/kmrlogs/error.log"
      CustomLog "D:/APPSERV/kmrlogs/access.log" common
      <Directory "D:/APPSERV/kmr">
      Options Indexes FollowSymLinks Includes
      AllowOverride All
      Order allow,deny
      Allow from all
      </Directory>
      </VirtualHost>

  • December 24, 2009 at 4:59 pm
    Permalink

    NameVirtualHost *:80

    ServerName localhost
    DocumentRoot D:/APPSERV/WAMP/www
    ErrorLog D:/APPSERV/WAMP/logs/error.log
    CustomLog D:/APPSERV/WAMP/logs/access.log common

    ServerName kmr.ru
    DocumentRoot D:/APPSERV/kmr/
    ErrorLog D:/APPSERV/kmrlogs/error.log
    CustomLog D:/APPSERV/kmrlogs/access.log common

    in browser i enter http://kmr.ru/
    but as result:

    Forbidden
    You don’t have permission to access / on this server.

    I did everything just as you tell me.
    What problem with that?

  • May 1, 2009 at 6:45 pm
    Permalink

    Hi,
    I’m having a strange problem with the virtual host setup on my server. I’m trying to setup a subdomain using virtual hosts, but I’m getting an “address not found” error when attempting to browse to the subdomain root. The strange thing is, that in the http-vhosts.conf file I commented out the lines for the main site and left the subdomain site uncommented. However, the main site still comes up, and the subdomain site cannot be found.

    Here’s what I have in the httpd-vhosts.conf file…

    #
    # Virtual Hosts
    #
    # If you want to maintain multiple domains/hostnames on your
    # machine you can setup VirtualHost containers for them. Most configurations
    # use only name-based virtual hosts so the server doesn’t need to worry about
    # IP addresses. This is indicated by the asterisks in the directives below.
    #
    # Please see the documentation at
    # <URL:[httpd.apache.org];
    # for further details before you try to setup virtual hosts.
    #
    # You may use the command line option ‘-S’ to verify your virtual host
    # configuration.

    #
    # Use name-based virtual hosting.
    #
    NameVirtualHost *:80

    #
    #ServerName http://www.mainsite1.com
    #ServerAlias mainsite1.com mainsite1
    #DocumentRoot C:/wamp/www/mainsite1
    #ErrorLog C:/wamp/www/mainsite1/logs/error.log
    #CustomLog C:/wamp/www/mainsite1/logs/access.log common
    #

    ServerName subdomain.mainsite1.com
    ServerAlias subdomain
    DocumentRoot C:/wamp/www/subdomain
    ErrorLog C:/wamp/www/subdomain/logs/error.log
    CustomLog C:/wamp/www/subdomain/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
    #

    • May 1, 2009 at 11:59 pm
      Permalink

      after edit vh, did you restart wamp to take effect? did you setup DNS for subdomain before creating vh? if not, follow this
      http://downloads.jlbn.net/

  • March 19, 2009 at 11:31 am
    Permalink

    Hi,

    I have with success installed more than one Virtual hosts on my system, but now i have also installed phpBB3 and wordpress, phpBB3 also works fine, but with wordpress i get page not found, however if i go to the local pc and type http://localhost/wordpress i get the first page, so what did i miss?

    All idea’s are welcome

    Thanks
    Marc

    • March 20, 2009 at 8:09 am
      Permalink

      Marc, wp use full path url so you have to use it w/ your domain; if no domain, use vh to make up a local domain, for example

      <VirtualHost *:80>
      ServerName wordpress
      DocumentRoot C:/wamp/www/wordpress
      </VirtualHost>

      so you can test it in your LAN as follows

      http://wordpress/

  • November 11, 2008 at 12:18 am
    Permalink

    I’m having trouble setting up virtual hosts. every time I remove the # from the second line and restart my server I get a yellow icon and can’t access my server.

    # Virtual hosts
    #Include conf/extra/httpd-vhosts.conf

    I have followed the guide making changes where nesassary and have tried following the guide exactly without success. Can anyone help me with this?

  • November 2, 2008 at 12:24 am
    Permalink

    Thank you, very clear and useful publication. But I still have a problem to setup Virtual Host for WAMP5 (v.2.0).

    I am having: (1)domain and (2) sub domain (sub1), similar as described in your manual:

    ServerName domain.com
    ServerName sub1

    On the computer that has WAMP installed (computer1) and all other computers inside my home LAN I am able to access the “domain” and “sub1”.

    http://domain
    http://sub1

    My problem starts when I am trying to access the server from the computer outside my home LAN:

    I am able to access the “domain”
    http://123.345.567.789 (OK, no problems)

    But I am unable to access “sub1”
    http://123.345.567.789/sub1 (NOT ACCESSIBLE)

    I am getting the following error message:

    “Not Found
    The requested URL /sub1 was not found on this server.”

    After some investigation I figured out that the address:

    http://123.345.567.789/sub1

    is pointing in:
    c:/wamp/www/domain/sub1
    But not in:
    c:/wamp/www/sub1

    (I just created a directory “c:/wamp/www/domain/sub1” and I am able to access the “index.php”)

    My virtual hosts settings are define as explained in the example:
    (Setup Virtual Host without Domain)

    NameVirtualHost *:80

    ServerName domain
    DocumentRoot C:/wamp/www/domain
    ErrorLog C:/wamp/www/domain/logs/error.log
    CustomLog C:/wamp/www/domain/logs/access.log common

    ServerName sub1
    DocumentRoot C:/wamp/www/sub1
    ErrorLog C:/wamp/www/sub1/logs/error.log
    CustomLog C:/wamp/www/sub1/logs/access.log common

    I will really appreciate someone help. Thank you.

    Solaris.

  • September 24, 2008 at 11:17 pm
    Permalink

    I don’t have domain, but I follow “Setup Virtual Host without Domain” and “httpd-vhosts.conf” is rewritten by your directions.
    I follow the tuts “Setup Virtual Hosts” and “Setup LAN & Worldwide Access” and everything works fine, when my Web IP is typed in a browser, it is redirected to the folder chosen in “httpd-vhosts.conf”:

    ServerName monospitovskoblato
    DocumentRoot “C:/wamp/www/mnb”
    ErrorLog “C:/wamp/www/mnb/logs/error.log”
    CustomLog “C:/wamp/www/mnb/logs/access.log” common

    ServerName sub1
    DocumentRoot “C:/wamp/www/sub1”
    ErrorLog “C:/wamp/www/sub1/logs/error.log”
    CustomLog “C:/wamp/www/sub1/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

    The problem is when after the Web IP is typed the name of the sub domain, like http://89.204.46.123/sub1. It not redirect to the folder set by VirtualHost, but as a subfolder of the main domain.
    In the tut is said that “On computers outside your LAN, access your websites as follows: If using Web IP:
    http://123.345.567.789 (to access domain.com)
    http://123.345.567.789/sub1 (to access sub1.domain.com)
    http://123.345.567.789/sub2 (to access sub2.domain.com)”
    and that “Except the codes for Virtual Host has minor change, everything else is the same”.
    Is something like this possible, or I must have real domain? (but, than why to use my Web IP?)

  • September 15, 2008 at 7:59 am
    Permalink

    Hey Alan,
    Those host files are only good if using in client computers, ie. your everyday compute use, but not quite good on server, and it actually slow down your server performances 🙁

  • September 9, 2008 at 7:40 am
    Permalink

    In step 5 and 6 of your guide to setting up virtual hosts you say we must replace the dummy codes (in the plural) and quote the four replacements. As a measure of protection we are using a hosts file from http://www.mvps.org/winhelp2002/hosts.htm so the file is large. Over 19,200 lines. 127.0.0.1 localhost is, however, the necessary first entry. Can you advise which are the ‘dummy codes’ please? Or, as an alternative should I insert the four codes you quote after the initial 127.0.0.1 localhost?

  • September 1, 2008 at 8:38 pm
    Permalink

    Alan, the domain is a real name that you have to buy and you can not buy the domain someone already bought while the local domain is a fake name which you can make up any name that you like; for example, you can not buy the domain microsoft.com but you can make up a local domain microsoft and use it within your LAN without any problem 😉

  • September 1, 2008 at 9:57 am
    Permalink

    Sorry the quote did not show up. Here it is again.
    -Remember, while the name for domain should be real which you have to buy or register, the names for domain, local domain, and sub domains are just the example names and you should change them to your desire names-.

  • September 1, 2008 at 9:55 am
    Permalink

    Hi
    I am very confused. In the first page of Install & setup Virtual Host you say —
    “”. —
    I have not been able to work out how to differentiate between domain and local domain. I am new at all of this and it is all very confusing. I have four machines on Windows Workgroup. WAMP is working fine on one of them but I would like to be able to access a “test” website, setup up on WAMP, from all of the machines. I understand that Windows Workgroup is not a domain, but simply cannot work out where to go from there without compromising the LAN security. I do not want to be seen from outside. Is this possible please?

  • August 26, 2008 at 2:43 pm
    Permalink

    I followed your guide to create virtual hosts domain, sub1 and sub2,

    wampsever can’t restart!!!!!!

    can you tell me what is the problem.?

    Thanks.

  • May 12, 2008 at 10:10 am
    Permalink

    Hello,

    I have faithfully followed your guide for setting up virtual hosting but it does not seem to work. I have no idea where I am going wrong.

    Tom

Leave a Reply