How to setup local subdomains using Wampserver

Developing code locally on your computer has some major benefits over using a web server. For one, it’s usually faster as you don’t have to wait for your file changes to upload to the web.

I’ll be using WampServer, a program that lets you run a local web environment (Apache, PHP & MySQL)

You’ll need to download & install WampServer before continuing with this tutorial.

This tutorial assumes WAMP is installed under C:\wamp. You may change this path to reflect your own installation if it differs.

Step 1: Create the folder which will hold your subdomains

For example. Create the following folder:
C:\wamp\www\subdomains

Each folder contained within the subdomains folder will essentially become a subdomain. For example:
example.localhost.com will point to C:\wamp\www\subdomains\example\

Step 2: Make sure httpd-vhosts.conf file is included.

Thanks to Dave Smith for pointing this out in the comments.

1) Open C:\wamp\bin\apache\Apache2.2.21\conf\httpd.conf (or choose Wampserver > Apache > httpd.conf)
2) Find the lines:

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

3) Change to:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Step 3: Configuring Apache VirtualHosts

1) Enable the alias_module and vhost_alias_module for apache.

Doing this will enable virtualhost aliasing in apache for your subdomains.

2) Open C:\wamp\bin\apache\Apache2.2.21\conf\extra\httpd-vhosts.conf

3) In the httpd-vhosts.conf file, you’ll most likely see some example data.  Replace everything with the following:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName localhost.com
    ServerAlias www.localhost.com
    DocumentRoot "C:\wamp\www"
    ErrorLog "logs\errors.log"
    <directory "C:\wamp\www">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from all
    </directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName localhost.com
    ServerAlias *.localhost.com
    VirtualDocumentRoot "C:\wamp\www\subdomains\%1"
    ErrorLog "logs\errors.log"
    <directory "C:\wamp\www\subdomains\%1">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from all
    </directory>
</VirtualHost>

So what’s going on with the code above?

Each <VirtualHost> tag contains a host definition.   The asterisk in <VirtualHost *:80> tells apache that any IP address can be used to access this host definition.  If you wanted to restrict it to just your computer, you could do <VirtualHost 127.0.0.1:80>

ServerName
ServerName localhost.com
The domain.  I use localhost.com. Just remember that whatever you choose to use will essential replace any real domains (EX: using google.com will not let you access the real google.com later)

ServerAlias
ServerAlias *.localhost.com
An alternate domain alias (usually www.localhost.com)

DocumentRoot
DocumentRoot "C:\wamp\www"
The absolute directory to your domain’s root (accessed by going to localhost.com)

ErrorLog Path to your error log.  This is optional.
ErrorLog "logs\errors.log"

VirtualDocumentRoot
VirtualDocumentRoot C:\wamp\www\subdomains\%1
The absolute directory for your subdomain, with a wildcard to define the subdomain’s name.  I use a wildcard %1 to get the name of the subdomain. example.localhost.com will point to C:\wamp\www\subdomains\example

<directory ________>
<directory "C:\wamp\www">
<directory "C:\wamp\www\subdomains\%1">
The directory permission definitions. Defined twice for both localhost.com and it’s virtual subdomains.

4) After making the changes to your httpd-vhosts.conf file, you must restart apache for the changes to take effect. Just click the WAMPSERVER icon in your Notification Area and choose “Restart All Services”.

Step 3: Updating Windows Host File

In order for you to access your localhost.com or example.localhost.com, you must first point these domains to your local IP address.  Windows unfortunately does not allow you to use a wildcard in the hosts file.  You will have to input each new subdomain into your hosts file for it to work in your browser.

1) Open C:\Windows\System32\drivers\etc\hosts using Notepad

2) Add a the following line to the bottom of your hosts file.

127.0.0.1       example.localhost.com

You have to do this for each domain & subdomain you wish to use. For example:
127.0.0.1       localhost.com
127.0.0.1       www.localhost.com
127.0.0.1       example.localhost.com
127.0.0.1       example2.localhost.com
127.0.0.1       mysubdomain.localhost.com

Test! Check if your subdomains work.

Open your browser and go to your local subdomain: example.localhost.com

Apache should now be serving files for that subdomain from C:\wamp\www\subdomains\example

Additionally: Custom Domain Definitions

If you ever wanted to create a custom domain definition that pointed to a folder outside of your “subdomains” folder, you can do that! Just open your httpd-vhosts.conf file (See step 2.2), and paste the following directly after NameVirtualHost *:80 and before the first instance of <VirtualHost *:80>.

This custom definition MUST be before your wildcard VirtualHost definition to work.

<VirtualHost *:80>
    ServerName mycustomlocaldomain.com
    ServerAlias www.mycustomlocaldomain.com
    DocumentRoot "C:\Documents\mycustomlocaldomain.com"
    ErrorLog "logs\errors.log"
    <directory "C:\Documents\mycustomlocaldomain.com">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from all
    </directory>
</VirtualHost>

And how the httpd-vhosts.conf should finally look with this custom definition:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName mycustomlocaldomain.com
    ServerAlias www.mycustomlocaldomain.com
    DocumentRoot "C:\Documents\mycustomlocaldomain.com"
    ErrorLog "logs\errors.log"
    <directory "C:\Documents\mycustomlocaldomain.com">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from all
    </directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName localhost.com
    ServerAlias www.localhost.com
    DocumentRoot "C:\wamp\www"
    ErrorLog "logs\errors.log"
    <directory "C:\wamp\www">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from all
    </directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName localhost.com
    ServerAlias *.localhost.com
    VirtualDocumentRoot "C:\wamp\www\subdomains\%1"
    ErrorLog "logs\errors.log"
    <directory "C:\wamp\www\subdomains\%1">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from all
    </directory>
</VirtualHost>

Need Help?

Apache configurations can be a tad confusing sometimes. If you get stuck, let me know in the comments below and I’ll do my best to assist you. Please let me know the steps you took so I can better determine the issue with your setup.

88 Comments

  1. Maron Aquillo

    Thanks for this wonderful tutorial mate. I really want to organize my projects by subdomains instead of subfolders. Looking forward for your other tutorials :)

    • Axertion (Author)

      Glad I could help :)

  2. I’m having trouble in the Custom Domain.
    This are some of my lines

    Servername lms.ninja-yan.dev
    DocumentRoot “C:\Users\ninja-yanz\learn”

    accessing the servername returns an error –> 403 Forbidden

    • Axertion (Author)

      Make sure you follow the correct capitalization on “ServerName” (note the capital N)

      Also make sure you have the directory definition in your httpd-vhosts.conf

      Your complete definition should look something like:

      NameVirtualHost *:80
      
      <VirtualHost *:80>
          ServerName lms.ninja-yan.dev
          DocumentRoot "C:\Users\ninja-yanz\learn"
          ErrorLog "logs\errors.log"
          <directory "C:\Users\ninja-yanz\learn">
              Options Indexes FollowSymLinks
              AllowOverride all
              Order Deny,Allow
              Deny from all
              Allow from all
          </directory>
      </VirtualHost>
      

      It’s also important that this definition is ABOVE any “dynamic” subdomain definitions you have. So paste this at the very top of your httpd-vhosts.conf THEN restart your Apache services. After that it should work ;)

  3. Kannan

    Hello Axertion,

    Thanks for your post. It was really helpful and I have created 2 subdomains in my local system. Please can you help how to configure subdomains for my server machine. I want to access subdomain from anywhere from the world. I have registered 2 sub domains for my site. The actual site domain refers to the WAMP server. But, Im not able to park the sub domains to my server.

    Thanks in Advance

    • Axertion (Author)

      What you’re wanting is to access your local WAMP server via a domain through the internet.

      To do this, you need to make sure your ISP doesn’t block incoming port 80 connections AND you have a static IP address (which you would point your subdomains to.

      After this, you open port 80 on your router’s firewall, have it point to your computer’s IP address (the computer hosting WAMPServer).

      Then you just point your subdomain DNS records to your static IP address.

      It’s a bit of a tricky setup, but I’ll write a tutorial explaining the process step-by-step if you want :)

      • rahul

        i m waiting for this tutorial

        like others i also face error 403 forbidden
        i just copy paste your code and i discover 1 error
        in ur
        Step 3: Configuring Apache VirtualHosts

        3) In the httpd-vhosts.conf file, you’ll most likely see some example data. Replace everything with the following:

        NameVirtualHost *:80

        ServerName localhost.com
        ServerAlias http://www.localhost.com
        DocumentRoot “C:\wamp\www”
        ErrorLog “logs\errors.log”

        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from all

        ServerName localhost.com
        ServerAlias *.localhost.com
        VirtualDocumentRoot “C:\wamp\www\subdomains\%1″ //// u forgot to write double codes here
        ErrorLog “logs\errors.log”

        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from all

        and after that it work fine for me

        thanks for the tut it help me alot

        • Axertion (Author)

          Double quotes are usually not necessary, but in some cases they can prevent misinterpretation from Apache. I’ll definitely add that to the tutorial ;)

  4. Thank’s for sharing :)

  5. is this correct

    DocumentRoot “c:/wamp/www/file-server-1.bunkerslife.com/”
    ServerName file-server-1.bunkerslife.com
    ServerAlias *.file-server-1.bunkerslife.com
    ErrorLog “logs/file-server-1.bunkerslife.com-error.log”
    CustomLog “logs/file-server-1.bunkerslife.com-access.log” common

    • Axertion (Author)

      Try this:

      NameVirtualHost *:80
      
      <VirtualHost *:80>
          ServerName file-server-1.bunkerslife.com
          ServerAlias *.file-server-1.bunkerslife.com
          DocumentRoot "C:\wamp\www\file-server-1.bunkerslife.com"
          ErrorLog "logs\errors.log"
          <directory "C:\wamp\www\file-server-1.bunkerslife.com">
              Options Indexes FollowSymLinks
              AllowOverride all
              Order Deny,Allow
              Deny from all
              Allow from all
          </directory>
      </VirtualHost>
      

      I think the issue you were having is:
      1) You should use back-slashes instead of forward-slashes when referring to the Windows filesystem. So I changed your DocumentRoot to C:\wamp\www\file-server-1.bunkerslife.com
      2) You need “directory” definition to let Apache know that it’s alright to view this folder.

      After making those changes, restart your apache service and test it out ;)

  6. its not working for me …………………..

  7. Kannan

    Hello Axertion,

    Thanks for the info. We are using port 8090 instead of 80. We have opened the port 8090 and the DNS is pointing to the static IP of my system. The firewall is removed for port 8090. I have 2 sub domains and mapped to 2 different folders in my server. But, when accessing both the sub domains, it redirects me to only one folder. i.e. domain 1 and domain 2 redirects me to the domain1 folder. Can you help me in this!!

    • Axertion (Author)

      What does your httpd-vhosts.conf file look like? It should look something like:

      NameVirtualHost *:8090
      <VirtualHost *:8090>
          ServerName mysite.com
          ServerAlias *.mysite.com
          VirtualDocumentRoot C:\wamp\www\subdomains\%1
          ErrorLog "logs\errors.log"
          <directory "C:\wamp\www\subdomains\%1">
              Options Indexes FollowSymLinks
              AllowOverride all
              Order Deny,Allow
              Deny from all
              Allow from all
          </directory>
      </VirtualHost>
      

      Also, if you are trying to load your domain locally via the internet (trying to visit mysite.com on the same PC wampserver is running), I’m not so sure if it will work. I do believe you still need to modify your Windows host file to point mysite.com to localhost. Otherwise you may experience an infinite loading loop.

      I’m also not sure how Apache handles external domains combined with it’s VirtualDocumentRoot. You may want to try defining each subdomain indiviually to see if that works first. You can do that like this:

      
      NameVirtualHost *:8090
      <VirtualHost *:8090>
          ServerName subdomain1.mysite.com
          DocumentRoot "C:\wamp\www\subdomain1"
          ErrorLog "logs\errors.log"
          <directory "C:\wamp\www\subdomain1">
              Options Indexes FollowSymLinks
              AllowOverride all
              Order Deny,Allow
              Deny from all
              Allow from all
          </directory>
      </VirtualHost>
      
      <VirtualHost *:8090>
          ServerName subdomain2.mysite.com
          DocumentRoot "C:\wamp\www\subdomain2"
          ErrorLog "logs\errors.log"
          <directory "C:\wamp\www\subdomain2">
              Options Indexes FollowSymLinks
              AllowOverride all
              Order Deny,Allow
              Deny from all
              Allow from all
          </directory>
      </VirtualHost>
      

      I need to do some experimenting with this to get exact answers that work. I’ll put together an article on my findings so it can help you and others :)

  8. Hi

    At first this didn’t work for me, but I remembered that the httpd-vhosts.conf is not always included by default; it is commented out in the httpd.conf.

    If the above isn’t working for you, then the following may be missing piece:
    1. Open C:\wamp\bin\apache\Apache2.2.21\conf\httpd.conf (or choose Wampserver > Apache > httpd.conf)
    2. Find the lines:
    # Virtual hosts
    # Include conf/extra/httpd-vhosts.conf
    3. Change to:
    # Virtual hosts
    Include conf/extra/httpd-vhosts.conf
    4. Save and restart Wampserver

    all the best, Dave

    • Axertion (Author)

      Thanks for pointing that out Dave. I didn’t experience this in my initial testing, but it seems other people are running into the same issue.

      I’ll update the article to include this information :)

    • Sean

      Great that’s what it was for me! :)

  9. Robert

    Hi,

    I followed your tutorial, however, I am still unable to view the subdomains. Instead, I am redirected to the main domain.

    The pastebin links below are to httpd.conf and httpd-vhosts.conf files on my machine:
    http://pastebin.com/nw2Cjxw9
    http://pastebin.com/xPj1htEU

    Please assist. Thank you!

    • Axertion (Author)

      Someone else pointed out that the httpd-vhosts.conf file is not always included by default in your httpd.conf file.

      After looking at your httpd.conf, that seems to be the case.

      On line 494 of your httpd.conf file, remove the hash (#) from the beginning of the line, save, then restart apache.

      This will include your httpd-vhosts.conf file into your main apache configuration file.

      • Robert

        I have included that line in now, and I am unable to view the site at all now.

        • Robert

          Oh… I intended for the subdomains folder to be outside of the www folder. pity it didn’t work out. I left the subdomains folder back into www folder and is working fine now.

  10. THANX Axertion
    i fixed that problem …….

  11. hey does anyone knows how to install a ssl certificate on apache on windows……..

  12. Ekrdos

    I configured a virtualhost on WAMP Server like you have described before, but there are already existing sites in my localhost, when I add the virtual host It works fine but when I try to load existing sites they fail.

    I get following response:
    The requested URL novirtualhostsite/index.php was not found on this server.

    Could you help me?

    • Axertion (Author)

      Hmm, hard to say what it could be without seeing what your httpd-vhosts.conf looks like. If you post what you have in that file, I might be able to determine what’s causing your previous sites from loading.

  13. Ekrdos

    Well, the thing is that I need to configure one virtual host http://www.virtualhost1.com and preserve localhost for already existent sites in localhost than could be accessed through http://localhost/site1.
    I need some like this:

    http://localhost/site1 => C:\wamp\www\site1
    http://localhost/site2 => C:\wamp\www\site2
    http://www.virtualhost1.com => C:\wamp\ www\virtualhosts\virtualhost1
    http://www.virtualhost2.com => C:\wamp\ www\virtualhosts\virtualhost2

    Is it possible? In my case http://localhost/site1.index.php marks was not found

    • Axertion (Author)

      Did you mean: http://localhost/site1/index.php? (note the forward-slash before “index.php”).

      Your VirtualHost configurations should not impair your default http://localhost/ access. Make sure you aren’t editing anything beyond what the tutorial outlines.

      If you are still having an issue, try completely clearning out your httpd-vhosts.conf file and restarting WAMP. See if you can access localhost from the browser.

      If you can, you must be using something your your vhosts file that is conflicting with the default localhost configuration. Try adding adding your vhost definitions one-by-one to determine which one it could be. Remember to always restart WAMP/Apache after making changes to the apache configurations.

  14. Avatapor

    I tried to make a custom domain but after following all these steps, going to it brings me to my wamp homepage like going to http://localhost

    • Axertion (Author)

      Make sure you completely restart Apache after making changes to the Apache configurations. I think that’s the most common reason why your configuration changes would not be working.

      • Avatapor

        I’ve restarted a ton, and checked to make sure the module is enabled but it seems like those settings aren’t even being read. If I take them out, the new domain still just takes me to the wamp homepage, I’m guessing because of the line I added to the hosts file

      • Avatapor

        Turns out I skipped step 2 =S

        • Axertion (Author)

          Haha yeah. I forget that step sometimes too. Glad you figured it out ;)

  15. Joao

    Great tutorial. Seemed to work fine. But when I try:

    $_SERVER['DOCUMENT_ROOT']

    in PHP it doesn’t return anything… do you know why not?

    • Axertion (Author)

      Weird. Works for me. Are you echoing it out, and it still returns absolutely nothing?

      What version of PHP are you running and did you make changes to your configuration beyond this tutorial? Also try creating a brand new virtual host pointing to a folder without any files in it. Create one .php file with the $_SERVER['DOCUMENT_ROOT'] variable echo’d and see if it works.

  16. david

    Hello
    just loaded Wampserver 2.2
    attempted to use the PHPADMIN

    error message

    Internet explorer cannot display the webpage

    i have windows 7

    r u able to help me please

    • Axertion (Author)

      I would check your /wamp/logs/apache_error.log or /wamp/logs/php_error.log to see what errors are being produced.

  17. Bryan

    Hi, my path to wamp is different and contains spaces. My Wamp stays orange and when I reset the httpd-vhosts.conf file it does start. So there’s something wrong with it.. How does the file act with spaces? I think there’s the problem:

    [code]
    ServerName localhost.nl
    ServerAlias http://www.localhost.nl
    DocumentRoot "D:\personal work\websites\- wamp\www"
    ErrorLog "logs\errors.log"

    Options Indexes FollowSymLinks
    AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from all

    ServerName localhost.nl
    ServerAlias *.localhost.nl
    VirtualDocumentRoot D:\personal work\websites\- wamp\www\subdomains\%1
    ErrorLog "logs\errors.log"

    Options Indexes FollowSymLinks
    AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from all

    [/code]

    • Axertion (Author)

      Make sure you are putting any variable value containing spaces within double quotes.

      For example, your VirtualDocumentRoot looks like this:

      VirtualDocumentRoot D:\personal work\websites\- wamp\www\subdomains\%1
      

      It should be like this:

      VirtualDocumentRoot "D:\personal work\websites\- wamp\www\subdomains\%1"
      

      It is a general rule of thumb that for web projects, you should not use spaces in folder names. I would recommend using underscores or dashes instead just to ensure the stability of your web application.

  18. Prabha

    Thanx a lot .

  19. Lee Thomas

    You, Sir are a F*****G HERO! I spent all morning following loads of tutorials on this and nothing was working, until I found yours. Thank you. Bookmarked and Tweeting about it right now.

    • Axertion (Author)

      You are very welcome :)

  20. Lee Thomas

    Once again thanks for this, can I make a small recommendation? instead of “Allow from all” use “Allow from 127.0.0.1″ instead of allowing anyone to access it it restricts it to your machine.

    • Axertion (Author)

      It’s a good recommendation, however this is more related to security/restrictions rather than the tutorial (setting up sub-domains). In reality, only people who are on the local network, and know the hostname and IP address of the computer running the apache server will be able to access the local server. It’s pretty unlikely someone will be able to access them, unless of course you give them those details ;)

  21. Shoaib

    Hi …
    i tried to setup up a sub domain of local host using the above tutorial the code is as follow :
    vhost
    ServerName localhost.com
    ServerAlias http://www.localhost.com
    DocumentRoot “E:\wamp\www”
    ErrorLog “logs\errors.log”

    Options Indexes FollowSymLinks
    AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from all

    ServerName localhost.com
    ServerAlias *.localhost.com
    VirtualDocumentRoot “E:\wamp\www\subdomains\%1″
    ErrorLog “logs\errors.log”

    Options Indexes FollowSymLinks
    AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from all

    and the similarly is the host entry to the file… basically i wana access my website in that domain.. how can i ? plz explain m a noob :(

    • Axertion (Author)

      Did you follow the tutorial completely? If you follow each step, and make sure it’s done correctly there is no reason it shouldn’t work. Make sure you’re not skipping out on essential steps, like restarting the WAMP server after modifying your host files.

      If you’ve done everything, please be sure to describe what is happening when you try to access the subdomain.

      • Shoaib

        When ever i try to hit the subdomain it again takes me to the login page of my site. .. but i dont want that to happen i am sending the session id to the subdomain but alas no beneefit…

        i had made test.localhost and it points to the same wamp page not the index.php of test.localhost which is in following path /subdomains/test/index.php

        Regards

  22. Matt

    Hello,

    Your tutorial is really great.

    It works.

    But, i would like to install WordPress MU on my local environment, i’m on windows 7 with wampserver 2.

    To generate my subdomains dynamically i would like to do in my ../etc/drivers/hosts with wildcards :
    127.0.0.1 mydomain.com *.mydomain.com
    Instead define all subdomains
    127.0.0.1 mydomain.com subdomain1.mydomain.com …

    Here my httpd.vhosts.conf :

    NameVirtualHost mydomain.com:80

    ServerName mydomain.com
    ServerAlias *.mydomain.com
    DocumentRoot “C:/wamp/www/myproject”
    ErrorLog “logs/errors.log”

    Options Indexes FollowSymLinks
    AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from all

    What do you think about?

    Thanks a lot.

    • Axel (Author)

      Hi Matt.

      As stated in my article on Step #3, Windows unfortunately does not support wildcard rules in the hosts file. You will have to manually enter each subdomain you create in your hosts file to access it locally.

  23. Soheil

    when i use print $_SERVER['DOCUMENT_ROOT']; in my page it shows C:/wamp/www
    I want $_SERVER['DOCUMENT_ROOT'] return my subdomain directory what should I do? :)

    • Axel (Author)

      It’s a know bug with mod_vhost_alias. People don’t recommend you use $_SERVER['DOCUMENT_ROOT'] for this exact reason, it can be unreliable in these situations.

      You can read up on this issue here, and hopefully use on of the suggestions provided in the comments on that page: https://issues.apache.org/bugzilla/show_bug.cgi?id=26052

  24. hi there,

    thanks axel for posting. i really like the idea of having my folders as subdomains so i can define my paths relative to the domain root.

    the only probems i encounter are in relation to rewrite rules.
    for instance: i´ve got a site that checks the request and if it matches a certain pattern then in redirects that request to my index.php where i have mvc magic going on.

    so the .htaccess in my www/subdomains/example/ looks like that:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^([a-zA-Z0-9]*)/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&action=$2&arg=$3 [NC,L]

    now when i try to call example.localhost.com/blog/showAll/123

    it tells me:
    The requested URL /subdomains/example/index.php was not found on this server.
    while example.localhost.com/index.php still gets me that php file…

    is this also in relation to the $_SERVER['DOCUMENT_ROOT']; problem?
    any suggestions on how to fix that?

    cheerio

    stephan

  25. Hi.

    Thanks for this awesome article. Got it to work with no problems!

    • Axel (Author)

      Awesome. Glad to hear :)

  26. João Cunha

    Hi! Thanks for the tutorial.

    All my projects are outside “C:\wamp\www\” and are accessible via aliases. E.G.:

    (the URL) http://localhost/project1
    (points to) C:\foobar\project1

    Suppose I would add a subdomain to project1 and place its files under the same directory:

    http://project1.com
    C:\foobar\project1

    http://mysubdomain.project1.com
    C:\foobar\project1\mysubdomain

    What would be the correct configuration to achieve this result?

    Thanks a ton.

    • Axel (Author)

      See the Additionally section of the tutorial. It covers setting up static definitions that aren’t inherently part of your Virtual Alias settings. Just make sure that the configurations you make for this custom subdomain are ABOVE the VirtualHost configurations.

  27. At Wamp Forum ( http://forum.wampserver.com/read.php?2,112136 )

    Hello friend,

    I create a Sub-Domain manager to manage domains and subdomains on my local machine.

    I was trying to find a way to manage domains over internet but found nothing,
    So, i decide to make my own script to manage my Domains.

    And i create it, and than think about to share i with others to make others work easy. :)

    As its hard for newbies to edit files and make it ready to use domains and sub-domains on WAMP.

    Download and enjoy…. :)

    ———————————————-

    Download: https://farmvilleitemcodes.com/darksam1995/wamp/Sub-Domain-Manager.zip

    ———————————————-

    If you find any bug or have any suggestion, Please Let know.

    Thank you.

  28. weathercraft

    HELLO axertion,

    im running a minecraft server on default port 25565 and i port foward too, and only i can access my server from the domain no one else please help.

    THXS :D
    ~Weather

    ***********************************LOGS*************************************

    *Port Foward
    Service Name Port Range Local IP Local Port Protocol
    My Server 25565 192.168.1.63 25565 BOTH
    Brand: ASUS RT-N66U

    *Minecraft Console Log

    2013-03-29 22:08:53 [INFO] Starting minecraft server version 1.5.1
    2013-03-29 22:08:53 [INFO] Loading properties
    2013-03-29 22:08:53 [INFO] Default game type: SURVIVAL
    2013-03-29 22:08:53 [INFO] Generating keypair
    2013-03-29 22:08:53 [INFO] Starting Minecraft server on *:25565
    2013-03-29 22:08:53 [INFO] Preparing level “world”
    2013-03-29 22:08:53 [INFO] Preparing start region for level 0
    2013-03-29 22:08:54 [INFO] Done (0.816s)! For help, type “help” or “?”
    2013-03-29 22:09:03 [INFO] weathercraft[/127.0.0.1:56284] logged in with entity id 262 at (-135.5, 92.0, 258.5)
    2013-03-29 22:09:29 [INFO] weathercraft lost connection: disconnect.quitting
    2013-03-29 22:12:03 [INFO] weathercraft[/127.0.0.1:56534] logged in with entity id 1084 at (-130.83448649007246, 72.0, 209.30000001192093)
    2013-03-29 22:12:10 [INFO] weathercraft lost connection: disconnect.quitting
    2013-03-29 22:13:35 [INFO] weathercraft [/127.0.0.1:56825] lost connection
    2013-03-29 22:14:37 [INFO] weathercraft[/127.0.0.1:56916] logged in with entity id 1275 at (-138.69999998807907, 71.0, 219.34375692059749)
    2013-03-29 22:17:22 [INFO] Opped weathercraft
    2013-03-29 22:17:26 [INFO] [weathercraft: Set own game mode to Creative Mode]
    2013-03-29 22:18:09 [INFO] [weathercraft: Set game difficulty to Peaceful]
    2013-03-29 22:18:43 [INFO] /8.23.224.110:22301 lost connection
    2013-03-29 22:20:29 [INFO] weathercraft lost connection: disconnect.quitting
    2013-03-29 22:28:25 [INFO] weathercraft[/127.0.0.1:57334] logged in with entity id 52473 at (-104.38675295736189, 79.0, 241.58443065499822)
    2013-03-29 22:34:39 [INFO] Kicked weathercraft from the game
    2013-03-29 22:34:39 [INFO] weathercraft lost connection: disconnect.endOfStream
    2013-03-29 22:34:42 [INFO] Unknown command. Try /help for a list of commands.
    2013-03-29 22:34:44 [INFO] Stopping the server
    2013-03-29 22:34:44 [INFO] Stopping server
    2013-03-29 22:34:44 [INFO] Saving players
    2013-03-29 22:34:44 [INFO] Saving worlds
    2013-03-29 22:34:44 [INFO] Closing listening thread
    2013-03-29 22:34:44 [INFO] Saving chunks for level ‘world’/Overworld
    2013-03-29 22:34:44 [INFO] Saving chunks for level ‘world’/Nether
    2013-03-29 22:34:44 [INFO] Saving chunks for level ‘world’/The End
    2013-03-29 22:34:44 [INFO] Stopping server

    *vhost config 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
    #
    # 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

    #
    # VirtualHost example:
    # Almost any Apache directive may go into a VirtualHost container.
    # The first VirtualHost section is used for all requests that do not
    # match a ServerName or ServerAlias in any block.
    #

    ServerAdmin webmaster@weathercraft.webs.com
    DocumentRoot “c:/wamp/www/weathercraftserver.html”
    ServerName weathercraft.webs.com
    ServerAlias mc.weathercraft.webs.com
    ErrorLog “logs/errors.log”
    CustomLog “logs/weathercraftserver.log” common

    Options Indexes FollowSymLinks
    AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from all

    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot “c:/apache2/docs/dummy-host2.example.com”
    ServerName dummy-host2.example.com
    ErrorLog “logs/dummy-host2.example.com-error.log”
    CustomLog “logs/dummy-host2.example.com-access.log” common

    wamp server version:
    Apache Version :
    2.2.22
    PHP Version :
    5.3.13

    • Axel (Author)

      I’m not certain what you’re asking. Having “others” access your custom subdomain is a bit more involved and out of scope to what this tutorial covers (local subdomains). There are tutorials that will tell you how to allow people to access your local environment through port forwarding and proper DNS routing.

      • weathercraft

        Thanks For Responding, ok ill see what i can do. And Yes I did Port
        fowarding part but the DNS part i don’t how to do it. But Thanks Any Way :)

      • weathercraft

        After Experminenting I found the way to make the domain… public
        Maybe You Should Add This To The Post

        To make the domain public goto the c:/windows/system32/drivers/etc/hosts file and change:

        127.0.0.1 localhost.com
        127.0.0.1 http://www.localhost.com
        127.0.0.1 example.localhost.com
        127.0.0.1 example2.localhost.com
        127.0.0.1 mysubdomain.localhost.com

        To

        YOUR EXTERNAL IP HERE localhost.com
        YOUR EXTERNAL IP HERE http://www.localhost.com
        YOUR EXTERNAL IP HERE example.localhost.com
        YOUR EXTERNAL IP HERE example2.localhost.com
        YOUR EXTERNAL IP HERE mysubdomain.localhost.com

        To Find Your External IP: Goto canyouseeme.org and look for Your IP: and replace YOUR EXTERNAL IP HERE

        Just Letting You Know, Hope this helps others.

        • Axel (Author)

          What you’re doing is mapping your own external IP to yourself, not actually making your site public. Other people won’t be able to type in http://www.yoursite.com and view it hosted from your computer.

          127.0.0.1 and Your external IP address are essentially the same thing for you, and you alone. They both point to the your local environment.

          Using 127.0.0.1 or your external IP will usually produce the exact same results.

          • weathercraft

            ok well, i guess goes back to my original question. What im trying ask i have a minecraft server, and im trying to point my subdomain to my minecraft server so that other players can connect to minecraft server but through my sub domain

            Thanks for your help Axel :)

            -weather

  29. Guy

    I know this is a little old of a post. But, I’d update the part of editing your host file to run notepad as administrator.

  30. Vdst

    That worked flawlessly, and took only 20 minutes.

  31. For anyone interested in not having to update the hosts file, I recommend checking out Acrylic: http://mayakron.altervista.org/wikibase/show.php?id=AcrylicHome. This allows you to do wildcard DNS matching as well as use regular expressions! Very handy for localhost devs :)

  32. Hey, just a kick word to thank you, didn’t knew about the vhost_alias module.

    You could use domains like 42foo.com or vcap.me to improve you configuration, no need to modify host file (But it doesn’t work if your internet is down).

  33. Chelsey

    Thanks so much for this tutorial!

    I’ve been able to get my localhost subdomains working using the method you outlined in the ‘Additionally’ section, but when I attempted to complete step 3 of your main instructions by restarting WAMP it fails to reload (orange icon). The error log states :

    ‘Parent: Received shutdown signal — Shutting down the server.
    Child 4676: Exit event signaled. Child process is ending.
    Child 4676: Released the start mutex
    Child 4676: All worker threads have exited.
    Child 4676: Child process is exiting
    Parent: Child process exited successfully’

    When I change the line ‘VirtualDocumentRoot’ to ‘DocumentRoot’ WAMP loads fine, but I get this error in the Apache log:

    ‘Warning: DocumentRoot [C:/wamp/www/subdomains/%1] does not exist’.

    I’d love to hear your thoughts – your subdomains folder implementation looks a lot cleaner and I’d prefer to use this method is I can get it to work!

    Many thanks!

  34. Kris

    Well, I’m not sure what I did, but the Apache service in wamp won’t start now. I forgot the to check the vhost_alias_module and when I went back to enable it I received the following message: Could not execute menu item (internal error) [Exception] Could not perform service action: The service has not been started.

    Any idea what to look at to get Apache started?

    Thanks!

    • Axel (Author)

      Work backgrounds from the changes you made and undo things one by one and test. From my experience, it could be you’re referencing an incorrect folder path in one of the alias configurations.

  35. William

    Hi thanks for the guide, my 2 domains seem to work great in localhost and site1.localhost, each go to their own directory, but when I go to my domains I get only site1 on both domains please help I’m at my wits end thanks

  36. Hi,

    I was working in local environment with multiple sites in my dreamweaver and i have used all variant of setting mentioned above but in as my site is localhost/mytend/web it works fine us for years. but as we trying to map images from subdomain as images.localhost/myintend/web it does not work as soon as we type the mention domain it redirect to http://www.images.localhost on internet.
    Give us some solution

  37. Pinkal vansia

    How to set up such virtual host when my local system is in LAN. And using port forwarding to forward requests to my system. i.e. 123.434.122.22:810

    Is it possible to have something like, sub-domain.123.434.122.22:810
    I did try but did not work. Thanks

  38. vani

    Hi , i have did everything same like you,but when i try to access the folder inside the subdomains,getting server not found page. kindly tell me where the problem is

  39. Snehanshu Phukon

    I want to know that how will I be able to do the above steps in a Webhost like Hostgator. If the above steps are not possible in Webhost, then what should I do. Actually I want to make a website that builds free website like Blogspot. I will need provide subdomains to the users like example.blogspot.com. Please help.

  40. Mubashar Ahmad

    I have changed following in httpd-vhosts.conf file but not working:

    NameVirtualHost *:80

    ServerAdmin localhost@localhost.com
    DocumentRoot “D:/wamp/www/”
    ServerName localhost
    ServerAlias localhost
    ErrorLog “logs/localhost-error.log”
    CustomLog “logs/localhost-access.log” common

    ServerAdmin webmaster@localhost.com
    DocumentRoot “D:/wamp/www”
    ServerName localhost.com
    ServerAlias http://www.localhost.com
    ErrorLog “logs/com-errors.log”
    CustomLog “logs/com-access.log” common

    ServerAdmin webmaster@localhost.com
    VirtualDocumentRoot “D:\wamp\www\subdomain\%1″
    ServerName localhost.com
    ServerAlias *.localhost.com
    ErrorLog “logs\sub-errors.log”

  41. Kishan

    If Your localhost PORT set 81
    ***** For localhost:81 *****

    NameVirtualHost *:81

    #
    # VirtualHost example:
    # Almost any Apache directive may go into a VirtualHost container.
    # The first VirtualHost section is used for all requests that do not
    # match a ServerName or ServerAlias in any block.
    #

    #ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot “C:/wamp/www”
    ServerName localhost
    ServerAlias localhost
    #ErrorLog “logs/dummy-host.example.com-error.log”
    #CustomLog “logs/dummy-host.example.com-access.log” common

    DocumentRoot “C:/wamp/www/subdomain”
    ServerName subdomain.localhost.com
    ServerAlias subdomain.localhost.com
    ErrorLog “logs/mydomain_error.log”

  42. Gregg

    Does this work with developing word press multi-site network locally? For some reason, I can’t get wordpress to allow me to use subdomains, only sub-directories.

  43. Jonathan Robert

    after following the steps above, this is what is happening

    Forbidden

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

    Apache/2.4.9 (Win64) PHP/5.5.12 Server at http://www.localhost.com Port 80

  44. If you want to keep `localhost` besides the new (sub)-domains, add the following to your `httpd-vhosts.conf` file:

    ServerName localhost
    DocumentRoot “c:\wamp\www”

  45. Bill

    Hi,

    You tutorial is great but I’m getting a 403 Forbidden when I try to access either localhost.com or any of the subdomains.

    Here is what’s in my vhost conf:

    NameVirtualHost *:80

    ServerName localhost.com
    ServerAlias http://www.localhost.com
    DocumentRoot “C:\wamp\www”
    ErrorLog “logs\errors.log”

    Options Indexes FollowSymLinks
    AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from all

    ServerName localhost.com
    ServerAlias *.localhost.com
    VirtualDocumentRoot “C:\wamp\www\subdomains\%1″
    ErrorLog “logs\errors.log”

    Options Indexes FollowSymLinks
    AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from all

    Any ideas on what is misconfigured?

    Thanks

  46. Thanks for the post. This worked at the first attempt. Thank you

Trackbacks for this post

  1. Setting Up (Development) Shop on Windows | 42umbrellas
  2. I Love WAMP | Bryan Hadro
  3. Subdominios en Wamp Server | Programación y otras utilidades
  4. Setup subdomains in WAMP « code.lifemock.com
  5. Leveling Up Web Development Wampserver

Leave a Reply to Soheil