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.
-
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. -
Search for “LoadModule vhost_alias_module” (without the quotes) and uncomment the
LoadModule vhost_alias_module modules/mod_vhost_alias.so
directive below. -
Search for “Virtual Hosts” (without the quotes) and uncomment the
Include conf/extra/httpd-vhosts.conf
directive below. -
Save and close the
httpd.conf
file.
-
-
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
. -
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.
-
Save and close the
httpd-vhosts.conf
file.
-
-
Update Your Windows Hosts File
-
Open your Windows hosts file located in
C:\Windows\System32\drivers\etc\hosts
. -
Add a new entry for the vhost you created in step 2.
-
Save and close the
hosts
file. -
Resart All Services in WAMP, pop open a web browser and access your new virtual host. Celebrate!
-
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.
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.
Run your text editor as Administrator. (Right click then Run As Admin)
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.
how i can access this site in my local network computer ???
It sounds like you did not complete step 3 above.
Thanks for the awesome article!
P.S. With WAMP server it looks like adding the thing to hosts file is not needed.
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/
Thanks for the tutorial. What editor do you use? It’s looks a lot nicer than notepad!
Nevermind, found it!
Is sublime text 3, http://www.sublimetext.com/3, with plugins is the best option
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.
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.
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.
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
Thank you ๐
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?
how can this be done in an online server. Thanks
Hi John, Thanx!!!
I did all your suggestions, and it really worked!!!!
this 3 step do, after restart server but it not start service show offline…..pls give any suggestion
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.
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
John, I forgot to mention, I use Wamp server 3.0
how to host a website using virtual server
Awesome
autoindex sorted out my errors. Project folder need not be in lowercase
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.
Thank you very much. Great tutorial. I don’t have much interest how to configure my local Apache server, so I follow your tutorial again and again ๐
thanks a lot
Hello John, I tried your tutorial, but I get this error message on my localhost:
The number of <Directory or does not match the number of ServerName in c:/wamp/bin/apache/apache2.4.23/conf/extra/httpd-vhosts.conf file
Can you please explain me what should I put in Directory tags, because I basically copied your example and put my IP address instead of yours for iPad….
Just wanted to say thank you for your guide, it helped me figure out what my issue was finally! Happy Easter!
It is not helping me. Pics attached for case study. What if I want to change IP of any virtual host, say it from 127.0.0.1 to 127.x.x.2 or reverse; and then access it through LAN.
Pics have been attached for case study.
https://uploads.disquscdn.com/images/4688e4d97b1cf08524043321cf4188510bc30fac51f8184777bbdac71e49df7e.png https://uploads.disquscdn.com/images/97de6b1f65e3bc07e3c9ea56eec717812f4a1254d214d03ca2ad403388dd300a.png https://uploads.disquscdn.com/images/ca61131a16782b2d7f4ef4aa24bb5a89a713c7086453344651df243bdb6591a2.png https://uploads.disquscdn.com/images/c32ca360999a588cc1a608512705c9cce8303f33ea46ed640e7e76ac55042e75.png https://uploads.disquscdn.com/images/13ecfc9347172387cf64ecca80894022456b05dd5345c5a0ddebfc6d1f897552.png https://uploads.disquscdn.com/images/a06b9eb529a3cc913156ad05ba917bdc6ae4164d89fb4f765d34e6b2081cbc98.png https://uploads.disquscdn.com/images/f8f4a48bd9ccbab9f0c5bc7cac8816a9f2a738b7353955e2f2d25ef2b180853e.png
hi john ,
i tried to create a virtula host like – 1mysite.local
but it throws me some syntax error
thanks.worked for me updating httpd-vhosts.conf
Hi John,
I tried all the above techniques but unfortunately no one works for me.
I tried to access URl like mysite.local/ & mysite.local:82/ but no luck, i am getting 502 Bad gateway error. with below error message :
DNS error
DNS error (the host name of the page you are looking for does not exist)
Please check that the host name has been spelled correctly.
I can access my localhost URL like localhost:82/, it is working for me.
following are the details of my config files :
httpd.conf
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_module modules/mod_proxy.so
Include conf/extra/httpd-vhosts.conf
ServerName localhost:82
Listen 0.0.0.0:82
Listen [::0]:82
httpd-vhosts.conf—————–
DocumentRoot “D:/wamp/www”
ServerName localhost
ServerAlias localhost
AllowOverride All
Options Indexes FollowSymLinks
Require local
DocumentRoot “D:/wamp/www/test”
ServerName mysite.local
ServerAlias http://www.mysite.local
AllowOverride All
Options Indexes FollowSymLinks
Require local
—————-etc/hosts—————–
127.0.0.1 localhost
::1 localhost
127.0.0.1 mysite.local
::1 mysite.local
One thing i noticed when i connected through WiFi network i can able to access URL mysite.local:82 it is working as expected. but when i switched to company LAN then its stop working.
Any help will be appreciated.
Thanks in Advance
Hi John, came across your page, I know that you’ll be able to help me with my wamp/ wordpress problem. I’m looking forward to learn more from you.
I have almost the exact same problem!
The difference is, I am able to access wamp server page from other devices, and the url is 192.168.0.103 (my “server” pc),
but when I try to access 192.168.0.103/mywptest, I get redirected to localhost/mywptest and I get message “canโt establish a connection to the server at localhost”
I was able to set up virtual host with your tutorial. Thank you !
Hi John i tried your tutorial but my why C:WindowsSystem32driversetchosts. is empty
my computer machine is throw error and eroor is that “VCRUNTIME140.dll is missing”
hi. i did. but message came that file in already in process. what should i do. plz guide me