HTDOCS folder of XAMPP server keeps the all the site file with the folder name as domain name. On URL recall "http://localhost/folder-name" site pages gets open into browser.
XAMPP Apache can be configured to keep more than one htdocs simultaneously by adding any number of Virtual Host.
If a folder name “D:\SITE” (located on hdd) is added as Virtual Host. On URL recall “http://site/folder-name” will open the requisite site in browser.
Difference between creating Virtual Host and changing Document Root directory in XAMPP
Creating Virtual Host is something different than changing the document root directory in XAMPP. Change in document root results in shifting of htdocs folder to another location with same or different name. In this case XAMPP is having a single document root to hold all the sites folders and will process the request coming only through URL “http://localhost/folder-name”.
Whereas adding virtual host to XAMPP results in multiple document roots to facilitate opening of site from multiple locations. It means both the below links will work.
Creating Virtual Host on XAMPP
Creation of Virtual host on XAMPP (for Windows OS) requires two steps.
1. XAMPP Apache configuration for virtual host:
Go To: "xampp\apache\conf\extra\httpd-vhosts.conf" and open the file. Here two things are required.
Note: make sure all "DocumentRoot" directory must exist and used "/" in address instead of backslash.
Go To: "C:\WINDOWS\system32\drivers\etc\" and open "hosts" file. Add as follows:
This will telling operating system what to do if entered http://site/ in your browser.
3. Restart the Apache through XAMPP Control panel to take the effect. Now
XAMPP Apache can be configured to keep more than one htdocs simultaneously by adding any number of Virtual Host.
If a folder name “D:\SITE” (located on hdd) is added as Virtual Host. On URL recall “http://site/folder-name” will open the requisite site in browser.
Difference between creating Virtual Host and changing Document Root directory in XAMPP
Creating Virtual Host is something different than changing the document root directory in XAMPP. Change in document root results in shifting of htdocs folder to another location with same or different name. In this case XAMPP is having a single document root to hold all the sites folders and will process the request coming only through URL “http://localhost/folder-name”.
Whereas adding virtual host to XAMPP results in multiple document roots to facilitate opening of site from multiple locations. It means both the below links will work.
http://localhost/folder-nameThis way you can have the choice which site to be put in which document root folder.
http://site/folder-name
Creating Virtual Host on XAMPP
Creation of Virtual host on XAMPP (for Windows OS) requires two steps.
- Configuration of XAMPP Apache.
- Configuration of Windows host.
1. XAMPP Apache configuration for virtual host:
Go To: "xampp\apache\conf\extra\httpd-vhosts.conf" and open the file. Here two things are required.
- Unable the virtual host by uncommenting (remove the # from beginning):
- Add the following lines for new virtual host. First add "localhost" as virtual host (because unableling virtual host will replace the default setting).
<VirtualHost *:80>Apache will open the mentioned directory at "DocumentRoot" on call of mentioned "ServerName".
ServerAdmin webmaster@localhost
DocumentRoot C:/XAMPP/HTDOCS
ServerName localhost
<Directory "C:/XAMPP/HTDOCS">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot D:/SITE
ServerName site
<Directory "D:/SITE">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
Note: make sure all "DocumentRoot" directory must exist and used "/" in address instead of backslash.
- Supplementary configuration (generally not required as it is default). Just have a glance for its presence. Go To: "C:\xampp\apache\conf\httpd.conf" (go around line no. 516) and uncomment (remove the # from beginning) the second line right after the #Virtual hosts to section now looks like this:
#Virtual hosts2. Windows host configuration for virtual host:
Include conf/extra/httpd-vhosts.conf
Go To: "C:\WINDOWS\system32\drivers\etc\" and open "hosts" file. Add as follows:
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
127.0.0.1 site
This will telling operating system what to do if entered http://site/ in your browser.
3. Restart the Apache through XAMPP Control panel to take the effect. Now
0 comments :
Post a Comment
Your remarks here!