XAMPP Virtual Hosts not working

37,415

Solution 1

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

Solution 2

Additionally make sure that the line

Include etc/extra/httpd-vhosts.conf

is not quoted out in httpd.conf

Solution 3

One thing I'd like to add here: For anyone who is sure everything is setup correctly, make sure you don't use any underscores in the alias string within your hosts file; for some reason it can't accept underscores.

Share:
37,415
Jacob Jewett
Author by

Jacob Jewett

On an adventure to learn everything; my head's about to pop().

Updated on September 17, 2021

Comments

  • Jacob Jewett
    Jacob Jewett over 2 years

    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.

  • Jacob Jewett
    Jacob Jewett almost 8 years
    Ok, I changed my vhosts file, restarted xampp many times, and I'm back at square one. Could you please, explain what larvel.test.com.at and how i'd accommodate my needs? I tried for ServerName vws.instancegaming and vws.localhost but none of then worked
  • Jacob Jewett
    Jacob Jewett almost 8 years
    I should also note that I changed my router settings to resolve instancegaming.net for my local needs but this problem has been insisting long before i did that.
  • Atiqur
    Atiqur almost 8 years
    Note-2 says its my folder name. Ok first delete all entries but localhost from httpd-vhosts.conf. and then try http://localhost in browser and check what is the error.
  • Jacob Jewett
    Jacob Jewett almost 8 years
    Refused to connect
  • Atiqur
    Atiqur almost 8 years
    off all service but apache from xampp controller and try again to localhost. and please update question with the content of httpd-vhosts.conf file.
  • Jacob Jewett
    Jacob Jewett almost 8 years
    ok disabled everything and tryed it...nothing; also updated the vhosts
  • Jacob Jewett
    Jacob Jewett over 7 years
    does anyone have a solution?
  • May Phyu
    May Phyu almost 7 years
    @Atiqur, bro could you please take a look at my question stackoverflow.com/questions/45173872/… ?
  • Atiqur
    Atiqur almost 7 years
    @MayPhyu Sure .
  • Top-Master
    Top-Master almost 5 years
    thanks, I had an issue like this but by me just the <VirtualHost *:80> ServerName localhost DocumentRoot "C:\xampp\htdocs" </VirtualHost> part was missing, and I do not know your Apache version, but for me the <Directory "C:\xampp\htdocs"> DirectoryIndex index.php </Directory> part was not required.
  • Omer
    Omer almost 4 years
    its commented for me ... if I uncomment the apache does not start