{"id":147,"date":"2009-07-21T17:11:11","date_gmt":"2009-07-21T11:41:11","guid":{"rendered":"http:\/\/vikku.info\/codesnippets\/?p=147"},"modified":"2009-07-21T17:19:52","modified_gmt":"2009-07-21T11:49:52","slug":"using-virtual-host-in-apache-like-virtual-directory-in-windows","status":"publish","type":"post","link":"http:\/\/vikku.info\/codesnippets\/apache\/using-virtual-host-in-apache-like-virtual-directory-in-windows\/","title":{"rendered":"using virtual host in apache like virtual directory in windows"},"content":{"rendered":"<p>by default we have our files stored in a user defined path like d:\\www\\xampp\\htdocs\\site1<br \/>\nwhen we access we give as localhost\/site1<\/p>\n<p>using virtual host option you can use like the following<br \/>\nconsider you have your site in d:\\www\\xampp\\htdocs\\site2<br \/>\nyou can access your site as &#8220;http:\/\/site2&#8221; or &#8220;http:\/\/site2.com&#8221; or &#8220;http:\/\/site2.local&#8221; &#8230; by updating the httpd.conf file<br \/>\nwhich will be present in the apache\/conf folder of your installation.<\/p>\n<p>edit your httpd.conf file and go to the bottom of it. and you can add like the following.<br \/>\ni assume that your default document root is d:\\www\\xampp\\htdocs<\/p>\n<pre lang=\"text\">\r\nNameVirtualHost 127.0.0.1\r\n\r\n<VirtualHost 127.0.0.1>\r\n   DocumentRoot \"d:\\www\\xampp\\htdocs\\site1\"\r\n   ServerName site1\r\n<\/VirtualHost>\r\n<\/pre>\n<p>before using this you have to do two steps<\/p>\n<p>one is restarting apache and the other is as follows<\/p>\n<p>since we are going to give http:\/\/site1 windows will connect to the internet to fetch the site but we have to inform windows<br \/>\nnot to connect to the www and instead connect to the local site1. for this you have to add the site1 in a windows file which<br \/>\nis stored in the following folder<\/p>\n<p>C:\\WINDOWS\\system32\\drivers\\etc<\/p>\n<p>the file name is &#8220;hosts&#8221; without extension<\/p>\n<p>you have to add the following line in the file &#8220;hosts&#8221;<\/p>\n<pre lang=\"text\">\r\n127.0.0.1       site1 or\r\n127.0.0.1       site1.com [if you want to access that way] or any of your wish\r\n<\/pre>\n<p>consider that you are having your site outside the default path of apache say d:\\mysite<br \/>\nthen you have to follow the steps below to include that<\/p>\n<pre lang=\"text\">\r\n<Directory \"D:\\mysite\">\r\n  Order Deny,Allow\r\n  Allow from all\r\n<\/Directory>\r\n\r\nand this besides the similar code\r\n\r\n<VirtualHost 127.0.0.1>\r\n   DocumentRoot \"d:\\mysite\"\r\n   ServerName mysite\r\n<\/VirtualHost>\r\n\r\n<\/pre>\n<p>include the above better before NameVirtualHost 127.0.0.1<\/p>\n<p>so you have two sites now and you can run your sites like the following<br \/>\ntype in the address bar after restarting apache as &#8220;site1&#8221; which will automatically be called as &#8220;http:\/\/site1&#8221; and mysite whic will be like &#8220;http:\/\/mysite&#8221;<\/p>\n<p>try it and enjoy&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>by default we have our files stored in a user defined path like d:\\www\\xampp\\htdocs\\site1 when we access we give as localhost\/site1 using virtual host option you can use like the following consider you have your site in d:\\www\\xampp\\htdocs\\site2 you can access your site as &#8220;http:\/\/site2&#8221; or &#8220;http:\/\/site2.com&#8221; or &#8220;http:\/\/site2.local&#8221; &#8230; by updating the httpd.conf file [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[19],"_links":{"self":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/147"}],"collection":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/comments?post=147"}],"version-history":[{"count":3,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/147\/revisions"}],"predecessor-version":[{"id":150,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/147\/revisions\/150"}],"wp:attachment":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/media?parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/categories?post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/tags?post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}