Virtual hosting is a method that allows one to run multiple web sites on a local computer. After setting it up, you would be able to access each web site using its own domain name.
In this tutorial, I will show how you can do it on WAMP, but other products are very similar, so you won’t have problems porting this.
Step 1: Open hosts
file, located in C:\Windows\system32\drivers\etc\hosts,
in you favorite text editor. Add a line similar to the one below and save the file.
127.0.0.1 mysite
Basically, this tells Windows to resolve IP 127.0.0.1 (which is localhost) to mysite.
For more sites, simply add more lines:
127.0.0.1 mysite 127.0.0.1 myothersite 127.0.0.1 localhost.localdomain
Step 2: Next, browse to C:\wamp\bin\apache\apache2.2.17\conf
and open httpd.conf
file in a text editor. In that, find a line that looks like this:
# Virtual hosts #Include conf/extra/httpd-vhosts.conf
Uncomment it (remove the # symbol) and save it.
# Virtual hosts Include conf/extra/httpd-vhosts.conf
Step 3: Browse to the folder C:\wamp\bin\apache\apache2.2.11\conf\extras
and open httpd-vhosts.conf
file in a text editor. Scroll to the end of the file and below code:
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot "c:/wamp/www" ServerName localhost ErrorLog "logs/localhost-error.log" CustomLog "logs/localhost-access.log" common </VirtualHost> <VirtualHost *:80> #ServerAdmin webmaster@mysite DocumentRoot "c:/wamp/www/mysite" ServerName mysite ErrorLog "logs/mysite-error.log" CustomLog "logs/mysite-access.log" common <directory "c:/wamp/www/mysite"> Options Indexes FollowSymLinks AllowOverride all Order Deny,Allow Deny from all Allow from 127.0.0.1 </directory> </VirtualHost>
You can see two directives for Virtual Host here. The first one preserves default localhost, so you can still access the WAMP dashboard, and the second one tells Apache where to look when a request for mysite is made. Rest of the code allows you to use .htaccess
on this domain.
Now restart Apache server, and you should be able to access http://mysite
to develop and test your site.
After completing this, you can run WordPress multisite on your local computer.
12 thoughts on “Run Multiple Websites in WAMP by creating Multiple Virtual Hosts”
Used wamp server for some program . never thought this !! will try to use this .. learning never ends
Yes, its a great piece of software. You will discover lots of other awesome features as well on exploring it.
whats the point of the hosts file? wouldnt this be for the public? you could access each side publicly.
and why use WAMP when a linux vm would perform better?
you can use a turnkey appliance.
Sir i am having a problem ,when ever i opening another site ,e.g base.com it is redirecting me to local host page , as i am doing to the same thing to another pc it works fine ,i tried to open base.com from local host it gave an error Unable to create file Cwampwwwwww.base.comhtdocswwwlogSERVER_NAMElogs.txt
HelP Plzz (
Wow… good idea
Is this hack no problem with wampp functionality?
Hi Kang, no problem at all, it is not a hack but just a feature that Wamp provides. I am using it on my computer as well.
oh, thank’s
i will try your tips for my localhost
I have done exactly what u have told but i am getting error message
Forbidden
You don’t have permission to access / on this server. can u tell why?
I am trying to set this up on my PC so that I can test multiple WP websites. However, I also run IIS 7.5. My PC runs Windows 7 64 bit OS. I have already tweaked the httd.conf file for listening on :8080 since IIS uses localhost. 127.0.0.1:8080 works. Where you have 127.0.0.1 mysite am I limited as to the number of sites I can create? Also step 3 has me baffled. Do I change the NameVirtualHost *:80 to NameVirtualHost *:8080 since that is the port that Apache uses? Please answer this as I am sure I am NOT the only one that is trying to set this up in this manner. Thank you.
Change the line “Deny from all” to “Allow from all” and you will get access. It worked for me.
I had to change the virtualhost port from 80 to 8080 to get it to work for me, but great post. Thanks!