While working on http://designerscouch.org worked on allowing users to have usernames as subdomains.
All went well on the server. But when I was trying to run the codebase on my local machine which had Apache2 running on windows I was not able to browse the site. After some research on the net and trials and errors succeeded in running the codebase on loacl machine.
Steps to set up named subdomains using Apache on Windows platform.
1) Open up your httpd.conf file in a text editor (wordpad or notepad) and add the following line at the bottom of the document.
Include conf/hosts.conf
The file, from the default installation can be found in the X:\Program Files\Apache Group\Apache2\conf folder.
Save the file.
2) Now create the hosts.conf file. Using your text editor create a new document and copy the virtual host example that is commented out in httpd.conf.
#NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#
Uncomment the text, remove the #’s and change to fit your need. In the example below there are settings on a made up domain name, localhost.com.
<VirtualHost *:80>
ServerAdmin admin@localhost.com
DocumentRoot "X:/Program Files/Apache Group/Apache2/htdocs"
ServerName *.localhost.com
ServerAlias *.localhost.com
</VirtualHost>
The above configuration allows you to put “anything” before the domain provided that the host exists in your HOSTS file.
Save the file as hosts.conf in X:\Program Files\Apache Group\Apache2\conf.
3) Now we modify the hosts file on windows OS to inform which hosts exists -
The HOSTS file is usually located in %SystemRoot%\system32\drivers\etc folder.
Open the file with a text editor and then add the following to match your virtual host settings above.
# PC (LOCAL)
127.0.0.1 localhost.com
127.0.0.1 www.localhost.com
127.0.0.1 suchetal.localhost.com
127.0.0.1 username2.localhost.com
Save the file and restart Apache. You should then be able to navigate to any of the URLs listed above.
Ex: http://suchetal.localhost.com
No comments:
Post a Comment