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.
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.
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.
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.
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.
127.0.0.1 localhost
127.0.0.1 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>
<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
</VirtualHost>
And finally, restart Apache from the Wamp tray icon menu.ServerAdmin admin@localhost
DocumentRoot “c:/wamp/www/”
ServerName localhost
ErrorLog “logs/localhost_error.log”
CustomLog “logs/localhost_access.log” common
</VirtualHost>
<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
</VirtualHost>
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.