How to create a virtualhost on Wamp server – Windows

Hello, if you want to create a virtualhost on your local machine (under Windows) using WAMP server and run your local php script/webpage under domain http://virtual1.localhost, here is an example and steps what you should do (an installation folder of WAMP server in this case is d:\wamp, the folder with your new app for example will be D:\wamp\www\newfolder1):

1. Open in text editor file named httpd.conf ( d:\wamp\bin\apache\apache2.4.9\conf)

2. Write following lines in file httpd.conf

<VirtualHost virtual1.localhost>
ServerName virtual1.localhost
DocumentRoot D:\wamp\www\newfolder1
<Directory D:\wamp\www\newfolder1>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

3. Inf you have problems with VirtualHost under Chrome or Opera, check the lines where are:

Listen 0.0.0.0:80
Listen [::0]:80

and try to replace it into:

Listen 127.0.0.1:80
#Listen 0.0.0.0:80
#Listen [::0]:80

and add another virtualhost for localhost

<VirtualHost localhost>
ServerName localhost
DocumentRoot d:\wamp\www
<Directory d:\wamp\www>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

4. Save the file changes.

5. Open in text editor (as administrator) file named “hosts” (C:\Windows\System32\drivers\etc)

6. Write following lines in file “hosts”:

127.0.0.1 virtual1.localhost

7. Save the file changes.

8. Restart Apache on WAMP server.

Leave a Reply

Your email address will not be published. Required fields are marked *