0
votes

Hi I have been trying for hours with many tutorials and I still not able to get the virtual host running on windows8 platform. I am using xampp 1.8.3. My xampp folder is installed as xampp2 in the c-directory

Step 1: I edited the \System32\drivers\etc\hosts file as such

127.0.0.1 xampp.local

127.0.0.1 localhost

Step 2: I enabled the following lines in httpd.config:

Include conf/extra/httpd-vhosts.conf
LoadModule vhost_alias_module modules/mod_vhost_alias.so

Step 3: I edited \apache\conf\extra\httpd-vhosts.conf

NameVirtualHost *:80

<VirtualHost 127.0.0.1:80>
    ServerAdmin [email protected]
    DocumentRoot "C:\xampp2\htdocs"
    ServerName localhost
    ServerAlias localhost
    <Directory "C:\xampp\htdocs">
        Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost 127.0.0.1:80>
    ServerAdmin [email protected]
    DocumentRoot "C:\Users\Sean\Documents\vhostprjs\foods"
    ServerName xampp.local
    ServerAlias www.xampp.local
    <Directory "C:\Users\Sean\Documents\vhostprjs\foods">
        Options All
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

Step 4: restarted xampp and tried localhost and it worked. But when I tried www.xampp.local\ chrome complains

Oops! Google Chrome could not find www.xampp.local

I really don't know what else to do.

4

4 Answers

4
votes

Use the following code... and edit accordingly in your http-vhosts.conf

NameVirtualHost *:80
NameVirtualHost *
  <VirtualHost *>
    DocumentRoot "C:\xampp\htdocs"
    ServerName localhost
</VirtualHost>


<VirtualHost *>
    DocumentRoot "C:\xampp\htdocs\your_site_directory"
    ServerName your_site_directory.dev
    <Directory "C:\xampp\htdocs\your_site_directory">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

And use this in your windows host file without the pound # sign infront

127.0.0.1       your_site_directory.dev 

The directory can be linked from any directory, not specifically from the htdocs folder and the server name can end in .anyname, but be becareful when using .coms and .nets, It may cause confusions while trying to access them.

But in case you still like to use .com or .net, which i usually do. This is how to get around with it, to access a .com you created for yourself (local) in your vitual host, this is how you do it from the address bar

http//your_site_name.com

And for your external .com

http://www.your_site_name.com
1
votes

Have you tried using forward slashes instead of backslashes?

NameVirtualHost *:80

<VirtualHost 127.0.0.1:80>
    ServerAdmin [email protected]
    DocumentRoot "C:/xampp2/htdocs"
    ServerName localhost
    ServerAlias localhost
    <Directory "C:/xampp/htdocs">
        Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost 127.0.0.1:80>
    ServerAdmin [email protected]
    DocumentRoot "C:/Users/Sean/Documents/vhostprjs/foods"
    ServerName xampp.local
    ServerAlias www.xampp.local
    <Directory "C:/Users/Sean/Documents/vhostprjs/foods">
        Options All
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>
1
votes

Oh, It was really for painful for me to get it work in Apache 2.4.9.I found a lot of tutorials, but I can not make it work.

MY SOLUTION IS FOR APACHE 2.4 AND ABOVE VERSION.I have tested it with Apache 2.4.9

You need to edit two files.PLEASE MAKE BACKUP OF THIS TWO FILE BEFORE YOU MAKE CHANGES.If you write anything wrong , your localhost will not work even you uninstall xampp and then again install xampp.

STEP 1:

Edit this file

C:\Windows\System32\drivers\etc\hosts

Open this file using "Run As Adminstrator" from Notepad(Very Important).You can do this by

Start Menu > Notepad >Right Click > Run As Adminstrator > Open file

add these two lines at the end of this file

127.0.0.1       testsite.dev
127.0.0.1       www.testsite.dev

Either you go testsite.dev or www.testsite.dev , it will now try to access from your local machine NOT from the web

STEP 2:

E:\xampp\apache\conf\extra\httpd-vhosts.conf

You can edit this file normally , there is no need to run this file as "Run As Adminstrator" Add the follwing lines at the end of this file

NameVirtualHost *:80
<VirtualHost *:80> 
    DocumentRoot "E:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "E:/xampp/htdocs/htc"
    ServerName testsite.dev
    ServerAlias www.testsite.dev
</VirtualHost>

I setmy xampp in E drive , so when you copy from here , make sure you change it according to your xampp installation.the Last part is little interesting.I am pointing out this potion

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "E:/xampp/htdocs/htc"
    ServerName testsite.dev
    ServerAlias www.testsite.dev
</VirtualHost>

Where can you find this code?In internet , you can find it in many places but might not work for you as that code will differentiate from your Apache version.SO WHAT"S THE SOLUTION?

At the end of file , you will see there are some commented lines already to show you a demo how to setup virtual host, just copy those lines and make necessary changes and it will work for you.I have attached a screenshot for better understanding

http://postimg.org/image/5pug9f42p/

0
votes

Oops! Google Chrome could not find www.xampp.local

The above error is related to name resolution. Chrome cannot find where the site "www.xampp.local" is. To resolve this, you have to add the fully qualified domain name to your hosts file:

127.0.0.1 www.xampp.local