Sai Gopal Wordpress Blog

saigopal wordpress blog

Saigopal's website

Saigopal's website

My Daughter Website

Weebly

Palwow

Freelance Jobs

Friday, March 12, 2010

Configuring Virtual host in Apache in Windows

Configuring Virtual host in Apache in Windows

Configuring a Virtual host in Apache in windows needs just two step.
First one: configure the apache
Second one: configure the DNS in windows.
First One:
The first file we’ll need to edit is the Apache httpd.conf file. Start your text editor and open the file. It will be in a sub-folder named conf of your Apache folder. For example, mine is here:
C:\Program Files\Apache\conf\httpd.conf
Now, for this example, we’ll assume that you have your web sites located in a folder on your C drive. Each web site has a sub-folder of its own under that folder, like this:
C:\test
We’re going to set up virtual hosts for those the site using the domain name test.local. That way, you’ll be able to tell at a glance whether you’re looking at the live site, or your testing site.
In reality, you can call the domain anything you want. You could just as easily name them test.com or test.net. I choose to use the convention of using the same domain name along with the .local TLD to simplify and minimize the typing needed to switch between the live site and the testing site. The only important point, and it’s really important, is that you NEVER use an actual, real, live domain name. If you used, for example, test.com for the local virtual host, you would never be able to actually reach the live site. All requests for the live site would be re-directed to your local virtual host.
Go to the very bottom of your httpd.conf file in your text editor. You should see an example of a virtual host there. Each line of that example will begin with an octothorpe (#). The octothorpe character marks the line as a comment, so the example is not executed. Add the following lines below that example:
NameVirtualHost 127.0.0.1


   DocumentRoot "C:\test"
   ServerName test.local
That’s all you need to do! Save and close the file. That will tell the Apache server everything it needs to know in order for it to serve the pages using the domain names test.local.
Second Change:
Obviously, if you typed http://test.local in your browser, it would not be found by your Internet provider’s DNS server. We’re next going to edit another file to work around that. The second file you need to edit is called hosts, with no file extension. It is a Windows system file and it will enable you to enter specific addresses for specific domains instead of using a DNS lookup. The normal location for this file is:
C:\WINNT\system32\drivers\etc\hosts
If you don’t find it there, do a search in your windows directory for the word hosts in the file name. The file you want is called hosts, with no file extension. The correct file will begin with the following lines:
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
Once again, in this file, the octothorpe character is a comment marker. Lines beginning with it are comments. In all likelihood, there will be nothing there, except for comments. If there are any other non-commented entries, leave them alone. Just go to the bottom of the file, below all the comments and any existing entries and add the following two lines:
127.0.0.1 test.local
That’s all you need to do there. Save and close the hosts file.
Lastly :
You’re almost done! The only remaining thing you need to do is to re-start the Apache server. You need to do this because Apache only reads the configuration file when it first starts up
Hope this will work for you.

2 Comments »

  1. [...] post by Tapos Pal Share and Enjoy: These icons link to social bookmarking sites where readers can share and [...]
  2. [...] Virtual host confguration in Linux (Ubuntu) Some days ago I have posted how to configure apache virtual host in windows. You can find it here. Now I will describe how to configure virtual host in Linux. It’s all [...]

No comments: