How to create a virtual host in wamp windows 10

0
7460
How-To-Create-a-Virtual-Host-in-Wamp-in-Windows---Featured-Image

Create a virtual host in wamp in windows 10 within 5 minutes by following the detailed guide provided in this article. To create a virtual host in wamp (in apache) is always a tricky task, however, with the help of this article you should be able to set up a virtual host on windows quickly and efficiently by following this wamp virtual host example provided in this article. 

Before diving directly into the set up of virtual host in wamp, at first, let’s find something about the Virtual Host and why it is beneficial to create a Virtual Host in wamp.

Why we should create a Virtual Host for development?

First and foremost, without a virtual host, it would be a little tricky to mention the relative path throughout the project. For instance, if you wanted to refer a link you may do <a href=”/link”>Link</a>.  This will redirect you to “localhost/link” instead of “localhost/project/link“.
Additionally, it makes easier to mimic subdomains as there is no need for involving .htaccess to do so.

How to create a virtual host in wamp?

To set up a virtual host on windows you can follow either of two steps mentioned below. As at the end of the day both methods do the same work, however, one is Wamp UI oriented whereas other is not.

  1. By adding details directly into the file
  2. Via Wamp localhost UI

Let’s take a look at our first method, where we need to update some files manually.

By adding details directly into the file.

As this tutorial is based on how to create a virtual host on wamp ( apache server ), we assumed that WAMP is already installed and ready to go. In case, if you haven’t installed yet, please install one first, from the official site of the wamp, and while installing always try to install the latest version of the wamp with latest stable version of PHP, Apache, and MySQL.

1. Make sure httpd-vhosts.conf is included

To confirm this, go to root wamp directory, followed by bin ➜ apache ➜ apache.x.x.x ➜ conf ➜ httpd.conf file from that directory.

D:\wamp64\bin\apache\apache2.4.35\conf

Please, replace “D:\” by the drive where wamp is installed on your computer. I am using “D:\” because I have installed wamp in “D drive”. In case if you have installed wamp in “C drive” in your computer replace “D:\” by “C:\“.

After opening the “httpd.conf” file search “vhosts“. Then, find the line

# Virtual hosts 
Include conf/extra/httpd-vhosts.conf

Make sure that the line Include conf/extra/httpd-vhosts.conf is not commented i.e, ‘#‘ is removed at the start of the line.

Include-httpd-vhosts-in-creation-of-virtual-host

2. Add servername and root directory to httpd-vhosts.conf

Find httpd-vhosts.conf located at wamp64\bin\apache\apache2.4.35\conf\extra 

(#Note: wamp64 is the root directory and this could be wamp only instead of wamp64 if you have installed x86bit version )

Now, copy and paste the code provided below to the httpd-vhosts.conf file.

# Noobietech
<VirtualHost *:80>
  ServerName noobietech.local
  DocumentRoot "d:/wamp64/www/noobietech/public"
  <Directory  "d:/wamp64/www/noobietech/public/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local
  </Directory>
</VirtualHost>

3. Add servername to the hosts

Next, you need to add the server name into the windows hosts file. This hosts file is located at “C:\Windows\System32\drivers\etc“. Open this hosts file as an administrator and add the following line to this hosts file.

127.0.0.1 noobietech.local

4. Restart all service or DNS of WAMP

Lastly, you need to restart the DNS of the wamp server. You can either left-click on the wamp server icon and restart all services. Or you can right-click on the wamp serverToolsRestart DNS.

Restart-all-services-wamp

Via WAMP UI

1) Include httpd-vhosts

Firstly, check if httpd-vhosts is included in httpd.conf file. You can access this file by left-clicking on the wamp iconapachehttpd.conf.

Open-httpd-conf-from-WAMP-menu-

Find the line and remove ‘#‘ if there is one at the beginning of the line.

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

2) Enable VirtualHosts sub menu

Next, on our mission to create a virtual host in wamp, we need to enable VirtualHosts sub-menu. To enable this, right-click on the wamp server iconwamp setting ➜ tick VirtualHosts sub-menu.

Enable-VirtualHost-sub-menu-WAMP

3) Add a new virtual host

Then, we need to add enter the desired server name like “sitename.local” or “sitename.dev“. Here, you can give any suffixes, however, it is recommended not to give those names that conflict with the real web address. And, also need to provide absolute address to create a virtual host in wamp.

To set up a new virtual host, left-click on the wamp server iconYour VirtualHostVirtualHost Management.

add-virtual-host-in-apache-wamp

There you need to enter, server name, and the absolute path of the dedicated project directory.

create a virtual host in wamp windows

After that, just click on “Start the creation of the VirtualHost” This might take a while and after that, it will notify about the successful creation of the virtual host

4) Restart DNS server

This is totally the same as in another restart method, where you need to restart all services or just the DNS of wamp server.

When you successfully create a virtual host in wamp, now-on you can access this site by entering the server name i.e. “http://noobietech.local” into the browser. Here, we are mentioning “noobietech.local” as we have used the exact name above. In case if you have used different suffixes like “.dev” then you need to enter as that.

Up to this point, we have successfully set a virtual host in wamp windows. Here, you saw the set up of virtual hosts by two methods. You can follow either of the steps. There is nothing that makes one step superior to the others. As even if you select the second method, it does the same thing for you in the background.

Now, let’s take a look at how we can delete them if we need to delete any virtual host in the future.

How to Delete a Virtual Host in Wamp?

To delete any wamp virtual host, you can erase everything you have added in steps 2 and steps 3 of the first method. However, if you want to delete a virtual host by using WAMP UI you need to follow the following steps:

  1. Left-click on the wamp server iconYour VirtualHostsVirtualHost Management.

    delete virtual host in wamp

  2. There you can find a button “Suppress VirtualHost form“. Click on that button.

    remove virtual host in wamp

  3. After clicking on the button, it will list all the available virtual host server name. Just select the virtual host which you want to remove the click on “Suppress VirtualHost“. 

    remove virtual host in wamp

Just after clicking on that button, the virtual host will be gone forever. Isn’t that so easy?

Ok, this was the end of the tutorial on how to set up a virtual host in apache server powered by wamp stack. 

 You can use this technique to create a virtual host in wamp for any project including Laravel as well as WordPress. If you got stuck anywhere while creating a virtual host in wamp, feel free to ask for support in the comment box. We will be more than happy to help you to set up a virtual host in wamp successfully.

If you enjoy our article, please share it with your colleagues, so that they could learn as well and set up a virtual host in wamp successfully and quickly without any hassle.

LEAVE A REPLY

Please enter your comment!
Please enter your name here