Friday, 22 June 2012

Creating a Subdomain On Localhost

Create subdomains through cPanel or DirectAdmin is quite easy, but what if you want to create subdomains on localhost or local computer?
Here’s a guide to make a subdomain on localhost using WAMP.

1. Open the file called ‘hosts’ in the directory C:\Windows\System32\drivers\etc\ using any text editor. Add a new line with subdomain you want to ceate (for example: subdomain.localhost), so that it becomes like the example below.      localhost      subdomain.localhost
Then save and close the file.

2. Open the ‘httpd.conf’ file from the Wamp tray icon menu or in the directory C:\wamp\bin\apache\Apache2.2\conf\, and find the following line.
#Include conf/extra/httpd-vhosts.conf
And un-comment it by removing the ‘#‘ from the start of the line.

3. Open the ‘httpd-vhosts.conf’ file in the directory C:\wamp\bin\apache\apache2.2\conf\extra\, you should find 2 virtual hosts in there (dummy-host.localhost and dummy-host2.localhost). Delete both (the entire block), then replace with the following line.
<VirtualHost *:80>
ServerAdmin admin@localhost

DocumentRoot “c:/wamp/www/”

ServerName localhost

ErrorLog “logs/localhost_error.log”

CustomLog “logs/localhost_access.log” common


<VirtualHost *:80>

ServerAdmin admin@subdomain.localhost

DocumentRoot “c:/wamp/www/subdomain”

ServerName subdomain.localhost

ErrorLog “logs/subdomain_error.log”

CustomLog “logs/subdomain_access.log” common

And finally, restart Apache from the Wamp tray icon menu.
If you run into problems after the restart, check the Apache error log. You may also need to restart your PC for Windows to pickup the changes you made to the Hosts file.
Related Posts Plugin for WordPress, Blogger...