Archive | Apache RSS feed for this section

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.

Advertisements