For Coders, This Virtual Host option is flexible in project making. There is lot of 3rd party tools available in the market like Xampp, Wamp, but those are set to be in proper directories or else it wont work.
If you are a php developer and need to organized your website projects on certain folder with each individual host address e.g. "test1.web", "test2.web", you can use any name for virtual host but don't use ".com" extension as this will tell the browser to look the website on the internet and not on your local pc.
This procedure assume that you have already installed the apache for windows, php module for apache
Step -1 :-
open the apache configuration file, note that better to install the apache on the root of drive C:
(c:/apache/) to make it compatible for short naming folder, ok so assume your apache was installed on the root drive c:
so open the configuration file on c:/apache/conf/httpd.conf and enable the virtual host module, scroll down to near end of configuration and you will find this
# Virtual hosts
# Include conf/extra/httpd-vhosts.conf
uncomment the vhost module by removing the hash character on fron of it so it will look like this
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Step - 2:-
open the virtual host configuration file on c/apache/conf/extra/httpd-vhost.conf and add this on the top area
<Directory c:/website/>
Options Indexes FollowSymLinks
Order Deny,Allow
Allow from all
</Directory>
where; c:/website is the root folder of all the site folder.
After the NameVirtualHost *:80 add this line below;
<VirtualHost *:80>
ServerAdmin admin@localhost
DocumentRoot c:/website/test1
ServerName test1.web
ErrorLog "error.log"
CustomLog "access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin@localhost
DocumentRoot c:/website/test2
ServerName test2.web
ErrorLog "error.log"
CustomLog "access.log" common
</VirtualHost>
Save the file.
Step 3:-
Configuration the windows host file for loop back address this will point your virtual host name to the local address, go to c:\Windows\System32\drivers\etc and find the "host" file
and add this configuration
127.0.0.1 test1.web
127.0.0.1 test2.web
and save the host file
Step - 4:-
Restart the apache usually from apache icon on the system tray, and after restarting just open your browser and enter the virtual host address e.g. site1.web
Note: the virtual host can only be access on your local pc so it cannot be access from other computer on the network, the only accessible is the top configured site treated as localhost, otherwise if you wish to access one of your virtual host to another computer you may change its port number aside from port 80
Info Help : Dario Mindoro.
Post a Comment