Search code examples
apachegoogle-chromexamppvirtualhost

XAMPP Virtual Hosts not working


Before marking this as answered, please read the entire thing because yes there is a good amount of these questions but NONE of the answers on them have worked at all.

For the last 6 months I've looked at around 50 different form posts here and around the web to try and get my XAMPP virtual hosts working.

Hosts File

127.0.0.1       localhost
127.0.0.1       vws.localhost
127.0.0.1       instancegaming.net
127.0.0.1       vws.instancegaming.net

http-vhosts File (Updated 7/26)

 # Virtual Hosts
 #
 # Required modules: mod_log_config

 # If you want to maintain multiple domains/hostnames on your
 # machine you can setup VirtualHost containers for them. Most      configurations
 # use only name-based virtual hosts so the server doesn't need to worry    about
 # IP addresses. This is indicated by the asterisks in the directives below.
 #
 # Please see the documentation at
 # <URL:http://httpd.apache.org/docs/2.4/vhosts/>
 # for further details before you try to setup virtual hosts.
 #
 # You may use the command line option '-S' to verify your virtual host
 # configuration.

 #
 # Use name-based virtual hosting.
 #
 # NameVirtualHost *:80
 #
 # VirtualHost example:
 # Almost any Apache directive may go into a VirtualHost container.
 # The first VirtualHost section is used for all requests that do not
 # match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
 #
 <VirtualHost *:80>
    ServerName localhost
    DocumentRoot "C:\xampp\htdocs"
    <Directory "C:\xampp\htdocs">
      DirectoryIndex index.php
    </Directory>
 </VirtualHost>

I'm at a loss of what to do, I've tried putting all fields to localhost then to instancegaming.net but nothing seems to work. I've read the Apache log and there's only SSL errors floating around.

When I try going to [ http:// ] vws.localhost, vws.192.168.0.47, vws.instancegaming.net all of which give the same error in chrome:

ERR_NAME_NOT_RESOLVED

Then I tried emptying chromes host cache, but that didn't help either. Sidenote: I reinstalled XAMPP 4 times trying to make this work.


Solution

  • Follow these steps if you are in windows environment (7 & 10 tested) with XAMPP:

    1. Add in hosts file [C:\Windows\System32\drivers\etc]
    127.0.0.1       vws.localhost
    127.0.0.1       instancegaming.net
    127.0.0.1       vws.instancegaming.net
    
    1. Add this in httpd.conf [C:\__Server\apache\conf] . though some says there are security risks with this but couldn't find a way without this
    <Directory />
        AllowOverride none
        Require all granted
    </Directory>
    
    1. Add these in httpd-vhosts.conf [C:\__Server\apache\conf\extra]
    <VirtualHost *:80>
         ServerName localhost
         DocumentRoot "C:\__Server\htdocs"
         <Directory "C:\__Server\htdocs">
             DirectoryIndex index.php
         </Directory>
     </VirtualHost>
    
    <VirtualHost *:80>
         ServerName tools.com.at
         DocumentRoot "E:\phpStorms\git\tools-class"
         SetEnv APPLICATION_ENV "development"
         <Directory "E:\phpStorms\git\tools-class">
             DirectoryIndex index.php
             AllowOverride All
             Order allow,deny
             Allow from all        
         </Directory>
     </VirtualHost>
     
     <VirtualHost *:80>
         ServerName laravel.test.com.at
         DocumentRoot "E:\laravel.test.com.at\public"
         SetEnv APPLICATION_ENV "development"
         <Directory "E:\laravel.test.com.at\public">
             DirectoryIndex index.php
             AllowOverride All
             Order allow,deny
             Allow from all
         </Directory>
     </VirtualHost>
    

    template of this

    <VirtualHost *:80>
         ServerName nameInHostsFile
         DocumentRoot "pathOfTheWindowsFileLocationWhichWillBeDocumentRoot"
         SetEnv APPLICATION_ENV "development"
         <Directory "pathOfTheWindowsFileLocationWhichWillBeDocumentRoot">
             DirectoryIndex index.php
             AllowOverride All
             Order allow,deny
             Allow from all      
         </Directory>
     </VirtualHost>
    

    Note 1: My xampp installed on C:\__Server location

    Note 2 : My folder name is laravel.test.com.at and its in E: drive E:\laravel.test.com.at

    Note 3: Always copy folder location from address bar in windows explorer, so there is no mistakes.

    Note 4: You must restart XAMPP after editing httpd-vhosts.conf every time.

    Note 5: Use uncommon part in url [i.e .com.at] so that it is unique and there is no issue resolving dns.

    Update: troubleshoot@Jacob Jewett

    After a fresh copy of XAMPP installation in C drive -

    1. just add/append these line in httpd-vhosts.conf file
    <VirtualHost *:80>
         ServerName localhost
         DocumentRoot "C:\xampp\htdocs"
         <Directory "C:\xampp\htdocs">
             DirectoryIndex index.php
         </Directory>
     </VirtualHost>
    
    <VirtualHost *:80>
         ServerName vws.localhost
         DocumentRoot "C:\xampp\vws"
         SetEnv APPLICATION_ENV "development"
         <Directory "C:\xampp\vws">
             DirectoryIndex index.php
             AllowOverride All
             Order allow,deny
             Allow from all        
         </Directory>
     </VirtualHost>
    
    1. Add append this in httpd.conf file
    <Directory />
        AllowOverride none
        Require all granted
    </Directory>
    
    1. ADD PATH variable for php [C:\xampp\php], and also check that there isn't another php path in the PATH variable.

    2. restart xampp and browse localhost