Apache: Setting virtual host on local system

24 Apr

It was up to this task since yesterday. I haven’t done this before, setting sub domain- virtual host on local system. I tried a lot yesterday but in vain, however when I came to office today I configured it successfully.

As I was stuck in the middle and feel lot of pain, so I better write it for those facing the same issue.

Why I was up to this task?

Well, actually my client was facing problem and reported that session is not working properly on domain and sub domain. So I was having no way other than setting virtual host.

However before leaving yesterday, I talked to my client that I am unable to solve this problem. He told me that I shouldn’t be worried about it because he will take care of this issue. The more important thing is that when I arrived today, I found that the problem has already been solved. Thanks to him for giving my favor.

Thought the problem has been solved, but still is worthy to write a small post here because I have successfully solved the problem.

Before going to discuss it, I would like to tell you that the configuration has been taken place on window so the paths may not be same.

Let have a look.

First of all you will need to open.

C:\xampp\apache\conf\extra\httpd-vhosts.conf

I assumed that you have install xampp.

And add following lines to httpd-vhosts.conf file.

NameVirtualHost *:80

<VirtualHost *:80>

ServerName localhost

DocumentRoot “C:/xampp/htdocs/”

ServerAdmin admin@localhost

</VirtualHost>

<VirtualHost *:80>

ServerName mysite.com.localhost

DocumentRoot “C:/xampp/htdocs/mysite/”

ServerAdmin admin@mysite.com.localhost

<Directory “C:/xampp/htdocs/mysite/”>

Options Indexes FollowSymLinks

AllowOverride FileInfo

Order allow,deny

Allow from all

</Directory>

</VirtualHost>

Here I have defined server localhost pointing to my default htdocs directory and another host mysite.com.localhost pointing to “C:/xampp/htdocs/mysite/”.

Another important thing is <VirtualHost *:80>

Here you would need to specify the port. In  my case its 80.

If you don’t specify the port on which apache listen, apache may take you to the same page for both the server. So be careful.

Next go to your Window/system32/dirvers/etc/ and open hosts file.

You will find

127.0.0.1       localhost

At the end of the file. Add following line next to it.

127.0.0.1         mysite.com.localhost

Reboot your system and you are done.

One Response to “Apache: Setting virtual host on local system”

  1. suresh.katiki April 6, 2011 at 11:34 am #

    If i use it can not opened.

    After remove below

    Options Indexes FollowSymLinks
    AllowOverride FileInfo
    Order allow,deny
    Allow from all

    it works fine.
    thank you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: