December 7, 2010

How to make Subdomains on Localhost

Sponsored Links

Developing websites on localhost may sometimes need making of sub domains. Installing and running another server for this purpose is useless, consumes more resources etc. So here is the technique to make sub domains on localhost.
So here is the technique to make sub domains on localhost.


You can also use this to host more than one site on localhost. i.e, you can host multiple sites situated on different folders.
PS: This is for Apache-Windows configuration. (If you have info about other Server-OS configs please let me know.)

Steps

First decide on the subdomain names...
for eg:
sub.localhost, sub2.localhost, alt.localhost , images.localhost etc..
You can also name www.name.com. (Please note that if there is a site with that name on the net, you wont be able to access that site on the internet.)

Second making these sites to point to 127.0.0.1, for this you can edit the HOSTS file on windows. See this about the HOSTS file.

Now add to HOSTS line
127.0.0.1 hostname
Egs:


127.0.0.1 sub.localhost
127.0.0.1 sub1.localhost
127.0.0.1 sub2.localhost
127.0.0.1 images.localhost
127.0.0.1 www.mysiteonmycomp.com



Next we have to assign each of these different URL's to different folders.
This is done on the apache conf file. (httpd.conf file situated in apache\conf\ directory)

Scroll all the way down the httpd.conf file until you reach about Virtual Hosts.
Add


NameVirtualHost *:80 #(This line was commented before)


ServerName subdomain name.localhost OR yoursite.com
DocumentRoot Path to the server root, See examples.
DirectoryIndex index.php index.html index.html index.htm index.shtml


Egs:



ServerName sub.localhost
DocumentRoot "C:/public_html/sub"
DirectoryIndex index.php index.html index.html index.htm index.shtml



ServerName images.localhost
DocumentRoot "C:/public_html/images"
DirectoryIndex index.php index.html index.html index.htm index.shtml



ServerName site.com
DocumentRoot "C:/public_html/site"
DirectoryIndex index.php index.html index.html index.htm index.shtml


Test the configurations (using apache -t)
All done!

0 comments:

Post a Comment

Have something to share? Comment it!

Not relevant? Take help with Search.

Custom Search

 

Updates on your Mobile

Updates on your Mobile
Go to m.techeguide.com from your mobile to get free access to updates, anytime & anywhere.

Recent Comments

Subscribed Yet?

Subscibe for email updates

© 2009 TecheGuide. The content is copyrighted to the author Mohit Tripathi and may not be republished on other websites. | View Privacy Policy |