How to Create a Virtual Host in WAMP

Creating a Virtual Host in Apache (WAMP).

Virtual hosts can be useful if you want to separate serving a website, or if you want to access your Apache website from another computer (in this case, we don't use a top-level domain, so this would be useful when viewing your local website from another device in your network.)

In this example, we will use the host mike-pc1. Where you see mike-pc1, replace with the name you would like your virtual host to be.

Step 1: Create the entry in your Windows hosts file. This allows your computer to respond to the new virtual name.

  • Open your hosts file in c:\Windows\System32\Drivers\etc and add the following at the end of the file and save it:
    127.0.0.1    mike-pc1
     
  • Open your httpd-vhosts.conf file and add the following at the end, then save it:
    <VirtualHost mike-pc1:80>
        DocumentRoot "${INSTALL_DIR}/www"
        ServerName mike-pc1
        <Directory "${INSTALL_DIR}/www">
            Options +Indexes +Includes +FollowSymLinks +MultiViews
            AllowOverride All
        </Directory>
    </VirtualHost>
     
  • Restart Apache

That's it! You should now be able to open your browser on your local computer and visit your new host!

Share this Post