Like most developers, I work locally. I develop on Windows (don’t judge) and run WAMP. In WAMP, websites are located in the C:\wamp\www directory. You can access a website at localhost/mysite. You all know this. The standard way of hosting sites in WAMP is restrictive. Setting up a virtual host (vhost) provides several benefits:

  • Virtual Hosts make URLs cleaner – localhost/mysite vs mysite.local.
  • Virtual Hosts make permissions easier – restrict access for a single vhost on a local network vs permitting access to all sites on your local network.
  • Some applications require a “.” in the URL (ahem Magento). While you can setup localhost.com/mysite by editing the Windows hosts file, creating a vhost is a better solution.

So, let’s setup a virtual host in WAMP.

  1. Include You Virtual Host Configuration File in Apache

    • Open your Apache configuration file located in C:\wamp\bin\Apache#.#.#\conf\httpd.conf, where #.#.# corresponds to the version of Apache that you are running in WAMP.

      Screenshot of the Apache configuration file in WAMP
      Apache Configuration File
    • Search for “LoadModule vhost_alias_module” (without the quotes) and uncomment the LoadModule vhost_alias_module modules/mod_vhost_alias.so directive below.

      Screenshot of the vhost_alias_module directive in the Apache  configuration
      Include Virtual Host Module
    • Search for “Virtual Hosts” (without the quotes) and uncomment the Include conf/extra/httpd-vhosts.conf directive below.

      Screenshot of the include virtual hosts directive in the Apache configuration file
      Include Virtual Host Configuration
    • Save and close the httpd.conf file.

  2. Update Your Virtual Host Configuration File

    • Open your Apache Virtual Hosts (vhost) configuration file located one directory down from the Apache configuration file directory in C:\wamp\bin\Apache#.#.#\conf\extra\httpd-vhosts.conf.

      Screenshot of the Apache virtual hosts configuration file in WAMP
      Apache Virtual Hosts
    • Add the configuration for your new vhost. While virtual host configuration is outside the scope of this article, I suggest you visit the Apache project’s documentation. It does a decent job of explaining the various configuration directives. I have included mine below with some comments as a starting point.

      Screenshot of a virtual host being added to Apache
      Add Virtual Host
    • Save and close the httpd-vhosts.conf file.

  3. Update Your Windows Hosts File

    • Open your Windows hosts file located in C:\Windows\System32\drivers\etc\hosts.

      Screenshot of the Windows hosts file
      Windows Hosts File
    • Add a new entry for the vhost you created in step 2.

      Screenshot of a new host being added to the Windows hosts file
      Add New Host
    • Save and close the hosts file.

    • Resart All Services in WAMP, pop open a web browser and access your new virtual host. Celebrate!

      Screenshot of the WAMP menu option to restart all services
      Restart All Services

      Screenshot of john-dugan.com running on the johndugan.local virtual host in WAMP
      johndugan.local Virtual Host
Posted by: John Dugan

Comments

  • Pingback: Accessing WAMP from Computers on Your LAN()

  • Pingback: Apache + BrowserSync Cross-Site Requests (CORS) Config()

  • thoroc

    why not use separate conf file for each vhost?

  • I would on a web server where there are more than a handful of virtual hosts. For my purposes of local development with just a few vhosts, I find it easier/simpler to keep the configuration in a single file. Once you get above 3 vhosts, then it makes sense to break things apart ~ IMHO.

  • JD

    Thanks. I appreciate your tutorial. I am having issues saving the hosts file. It says “acceess denied”. I am not sure how to change permissions on the file. The way I tried, the options are greyed out. I am running as administrator.

  • Hey JD,

    As you indicate, it sounds like a simple permissions issue. You’ll want to confirm that you have write permissions on the file. If you are running as administrator, I’m not sure why you are still running in to problems.

    Perhaps when you come across a solution you could update this thread to help out others that encounter the issue.

  • Pingback: Accessing WAMP from a Virtual Machine()

  • Vivek Shakya

    Run your text editor as Administrator. (Right click then Run As Admin)

  • intrigueintelligence

    I’m using Win7 and all my asp.net applications are running at port 80

    I’ve WAMP installed at c:wamp and i’ve my php project folder under c:wampwww as proj1,proj2 etc.,

    Now i tried to create virtual host with below steps

    1) edited ‘hosts’ file and added below

    127.0.0.1:9091 testsite1.mymachine.com

    2) Opened the file “httpd.conf” at “C:/wamp/bin/apache/Apache2.2.22/conf/” and uncommented the line “Include conf/extra/httpd-vhosts.conf”.

    3) Opened the file “httpd.vhosts.conf” at “C:/wamp/bin/apache/Apache2.2.22/conf/extra” and added the below

    Order Deny,Allow
    Allow from all

    after the above code added the below

    DocumentRoot “C:/wamp/www/proj1”
    ServerName testsite1.mymachine.com

    4) Saved all the above edited files from step 1 through step 3, restarted the wamp server services.

    But, i’m unable to access my proj1 using “testsite1.mymachine.com”. did i missed anything ? Also please take note by using “http://localhost:8081/” i’m able to see wampserver – server configuration page.

  • kowshik

    how i can access this site in my local network computer ???

  • It sounds like you did not complete step 3 above.

  • yavou

    Thanks for the awesome article!

    P.S. With WAMP server it looks like adding the thing to hosts file is not needed.

  • Jerome

    can this be shared on other computers within the nework?

  • Absolutely! The link below explains how. 🙂

    https://john-dugan.com/access-wamp-from-lan-computers/

  • Chris

    Thanks for the tutorial. What editor do you use? It’s looks a lot nicer than notepad!

  • Chris

    Nevermind, found it!

  • fabio sanchez

    Is sublime text 3, http://www.sublimetext.com/3, with plugins is the best option

  • Pingback: 14.04 – Is it possible to create a virtual host on a virtual machine? | Asking()

  • Marco Luciano

    Hi i have a question when i use for my site ( Magento with xampp on windows) other pc change in address bar the domain name with localhost ip

    ex
    PC with server ip 192.168.1.100 (mydomain.it created with your guide)
    other PC
    i write mydomain.it and after 2 second become 127.0.0.1 on other pc, how can i fix it?

  • You need to update your `hosts` file on all client machines that will be connecting through the LAN to your XAMPP server.

    The hosts file is located at: `C:WindowsSystem32driversetchosts`. Open it as admin with notepad and add the entry shown below.

    Depending on your virtual host setup, you may also need to explicitly allow connections from all client machines. See line 61 in the screenshot of my code editor in step 2.

  • Paul Ankomah

    Hello John, Great tutorial, however Is there a way to make wamp server installation portable?

  • Hi Paul,

    There really isn’t. Tools like Vagrant and Docker have popped up more recently to address that issue. I have yet to move to one. The return on my time for moving would be nil at this point. However, if I were in a position where I needed to deploy the same environment across several machines, I’d strongly consider making the switch.

  • Ashmad Alok

    After done this all changes. I restarted my wamp server but it stuck… local host is also not working.

    My purpose is I have multiple website on wamp server installed on windows 2012 and for each website I have multiple domains but they are from other domain providers. SO I want to host multiple websites on single wamp server and connecting them with domains..can you help me with that?

  • Windows 2012? I don’t believe WAMP officially supports Windows Server.

    Regarding your domain issue, you’ll need to properly configure DNS with your registrar. Frankly, I have no clue what you are trying to do. I would not advise attempting to host sites publicly on Windows Server with WAMP. Just use IIS. Really though, if you can afford a license for Windows Server, you can probably afford good managed web hosting.

  • Ashmad Alok

    Hey

    John, I now left the idea to use wamp server. I installed IIS.

    Here is what I am trying to do for my client-
    He has multiple domains in 1&1, arviex around 10 websites build in asp.net and WordPress and PHP. He has hosting on hostingsv.net.

    Now what client want is close hostingsv.net. He purchased windows server 2012 cloud and want his all domain direction to Windows Server cloud.
    What I did-
    I migrated all websites to windows Server from hostingsv. All website working fine on windows servers localhost IIS.

    My Problem-
    Windows Server has only one public IP. I am not able to find the way to direct all domains to windows server 2012 cloud where I migrated all websites data and databases.

    What I tried-

    I tried to changed one domains host IP to windows server public IP but it is not working.

  • For the record, I would not (and don’t) host my own sites without deep domain knowledge.

    That said, I know as much as the next guy (or less) about IIS. I’m sure there is a way to setup virtual hosts like you can on NGINX and Apache. That’s what you’re after it sounds like. IPs are scarce these days, hosting multiple sites on the same IP is very common – it’s how every shared hosting package is setup.

  • Hi, Can you help, please. I’ve followed through the post twice, but each time when I put “website.local” into the URL bar, it does a Google search >. copied your vhost file, with my own details > copied the servername into the host file…. and restarted wamp

  • Ahmed Anas

    Thank you 🙂

  • Azhar

    Hi john i have done all the changes but i have run my localhost on port 8080(localhost:8080). After doing changes my wampp server not starting why?

    i make my virtual host as

    ServerAdmin azhar@xyz.com

    DocumentRoot “C:/wamp/www/Project/public/”

    ServerName xyz.abc.local

    ServerAlias http://www.xyz.com

    ErrorLog “C:/wamp/www/Project/logs/log.txt”

    CustomLog “C:/wamp/www/Project/logs” common

    Deny from all

    Allow from 127.0.0.1

    Can you help me?

  • Nsima Edeheudim

    how can this be done in an online server. Thanks

  • flutschit

    Hi John, Thanx!!!
    I did all your suggestions, and it really worked!!!!

  • neeraj patel

    this 3 step do, after restart server but it not start service show offline…..pls give any suggestion

  • filigreti

    i have a c# program that uses wamp server as its database, connection is fast on the main server, but my problem happens when another system tries to access wampserver from the mainserver, the application on the secondary system takes time to load…pls i need help

  • WAMP server is not a database. The question is too broad to give you any helpful advice.

  • Check your logs. They are always the first place you should go to diagnose issues like this.

  • Joe Lehman Jr.

    John,
    First off, my wamp server is on port 81. Attached is a screen shot of my httpd-vhosts.conf & hosts files. When I go to pug.local it gives me an 404 error. What am I doing wrong? By the way I use WAMP Server 3.0

  • Joe Lehman Jr.

    John, I forgot to mention, I use Wamp server 3.0

  • Deepak

    how to host a website using virtual server

  • unloco mqx

    Awesome

  • autoindex sorted out my errors. Project folder need not be in lowercase

  • Andrew

    Hey John, Check this out from a dutch developer: http://www.usbwebserver.net/en/. Works like a charm and I believe is the answer to the posed question.