Thursday, November 7, 2013

XAMPP HTTPD Virtual Hosts Configuration


-----
1) INTRODUCTION
2) EDIT HOSTS file
3) CREATE WEB ROOT DIRECTORY
4) EDIT httpd-vhosts.conf
5) RESTART WINDOWS

1) INTRODUCTION

1.2) The term Virtual Host refers to the practice of running more than one web site (such as company1.example.com and company2.example.com) on a single machine. Virtual hosts can be "IP-based", meaning that you have a different IP address for every web site, or "name-based", meaning that you have multiple names running on each IP address. The fact that they are running on the same physical server is not apparent to the end user. (refer http://httpd.apache.org/docs/2.2/vhosts/)

2) EDIT HOSTS file

2.1) Before a Virtual Host is configured in Apache environment, its address (IP No. and Domain Name) must be registered to the host computer first. This is accomplished by editing a Hosts file.
2.2) By definition, the hosts file is a computer file used by an operating system to map hostnames to IP addresses. The hosts file is a plain text file, and is conventionally named hosts. (http://en.wikipedia.org/wiki/Hosts_(file))
In windows, the file can be found at %SystemRoot%\system32\drivers\etc\hosts
In Linux, the file can be found at /etc/hosts
2.3) Using notepad++ open the hosts file and edit as follows:
(add the name “testproject.local”)

3) CREATE WEB ROOT DIRECTORY

3.1) Web root directory for testproject.local can be located at anywhere in the computer storage.
3.2) For example, C:\projects\testproject.local\htdocs 
3.3) Create a simple content for index.php for testing purpose as shown above.

4) EDIT httpd-vhosts.conf

4.1) At line no. 19, remove the # symbol to enable NameVirtualHost directive.
4.2) Add new codes to the bottom of the existing codes.
Notice that there are two VirtualHosts defined; one for the localhost and the other one for testproject.local.
<VirtualHost *>
    ServerAdmin admin@localhost.com
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>
<VirtualHost *>
    ServerAdmin admin@localhost.com
    DocumentRoot "C:/projects/testproject.local/htdocs"
    ServerName testproject.local
         <Directory "C:/projects/testproject.local/htdocs">
                        AllowOverride all
                        Order allow,deny
                        Allow from all
                        Require all granted
         </Directory>        
</VirtualHost>

5) RESTART WINDOWS

5.1) Windows must be restarted for the new virtual host address to be recognized.
5.2) After running the Apache Server, check in the Web Browser that the following output is displayed.

No comments:

Post a Comment

Labels