When developing websites on a local WAMP installation, I often need control over the DNS. It is no problem to add a hostname to the Windows hosts file, but a wildcard in the domain does not work. For example you need a wildcard domain when installing WordPress Multisite locally with subdomains. This article has the solution to add wildcards to your local WAMP installation, without installing Bind or other heavy DNS solutions.
Configuring WAMP for wildcard domains
If you not WAMP installed already, you can find here: www.wampserver.com/en/
After the download you can install it with the default parameters.
After installation it is possible to open a webpage at http://localhost/
Enable Virtual hosts on WAMP
When WAMP is running, you will see a green icon on the task bar. To enable virtual host, we need to configure it.
Left-click on the green WAMP icon and go to menu: Apache->httpd.conf
Press in Notepad Ctrl-F and search for: httpd-vhosts
Remove the ‘#’ before the Include to include the httpd-vhosts.conf file
# Virtual hosts Include conf/extra/httpd-vhosts.conf
Adding Virtual hosts on WAMP
To add the Virtual hosts, open Notepad, open file and browse to this file (default installation):
In httpd-vhosts.conf you can add the virtual hosts you need, here is an example for two virtual hosts. You can put here also more virtual hosts. Special in the configuration is the ServerAlias to provide the wildcard (‘*’) in the domain.
<VirtualHost *:80> DocumentRoot "C:\wamp\www" ServerName mydomain.local ServerAlias *.mydomain.local </VirtualHost> <VirtualHost *:80> DocumentRoot "C:\wamp\www" ServerName myotherdomain.local ServerAlias *.myotherdomain.local </VirtualHost>
Now save the httpd-vhosts.conf file and restart the WAMP server.
Configuring DNS wildcards with Acrilic DNS Proxy
I was looking for a tool like this for a long time. Normally I had to configure Dnsmasq on a Linux machine, but with Acrylic it is a lot more easier and all local on a Windows machine.
Download Acrilic DNS Proxy from Sourceforge: sourceforge.net/projects/acrylic/
After installation go to menu:
Start->Programs->Acrilic DNS Proxy->Config->Edit Custom Hosts File
Add the folowing lines on the end of the file:
127.0.0.1 *.localhost 127.0.0.1 *.local 127.0.0.1 *.lc
Now you need to restart the Acrilic DNS Proxy service. Go to menu:
Start->Programs->Acrilic DNS Proxy->Config->Restart Acrilic Service
Do not forget to change your Network adapter settings:
- go to menu: Start->Control Panel->Network and Internet->Network Connections
- Right-click on your current network adapter and select Properties
- Now select Internet Protocol Version 4 and click on the Properties button
- Fill in the localhost IP number (127.0.0.1) at the DNS section (see picture) and press OK.
[shashin type=”photo” id=”1933″ size=”medium” columns=”max” order=”user” position=”center”]
The result and WordPress Multisite
Now you are able to ping a domain like: hello.mydomain.local. Also to run a website with domain names like hello.mydomain.local locally.
It is also possible to run a site like WordPress.com. This is a WordPress installation with multiple subdomains under it. Previously it was called WordPress MU. Since WordPress 3.0, multisite is integrated into the normal release of WordPress.
How to configure WordPress Multisite you can read in this article: Configuring WordPress 3 with Multisite and second level domains