11

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.

Ram Ghadiyaram
  • 28,239
  • 13
  • 95
  • 121
Jacob Jewett
  • 349
  • 2
  • 4
  • 18
  • `ERR_NAME_NOT_RESOLVED` is not apache related, something is wrong with the name resolution. What happens if you try `ping vws.instancegaming.net` from command line? – Dusan Bajic Jul 23 '16 at 07:43
  • I get the following: C:\Windows\System32>ping vws.instancegaming.net Pinging vws.instancegaming.net [127.0.0.1] with 32 bytes of data: Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Ping statistics for 127.0.0.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms – Jacob Jewett Jul 23 '16 at 08:15
  • Can you download [curl](http://winampplugins.co.uk/curl/) and try `curl -v vws.instancegaming.net` from cmd line? – Dusan Bajic Jul 23 '16 at 08:22
  • Result from Curl: C:\Users\JAcOb\Desktop\stuff\curl>curl.exe -v vws.instancegaming.net * Rebuilt URL to: vws.instancegaming.net/ * Trying 127.0.0.1... * connect to 127.0.0.1 port 80 failed: Connection refused * Failed to connect to vws.instancegaming.net port 80: Connection refused * Closing connection 0 curl: (7) Failed to connect to vws.instancegaming.net port 80: Connection refused – Jacob Jewett Jul 23 '16 at 18:04
  • https://stackoverflow.com/questions/27754367/how-to-set-up-apache-virtual-hosts-on-xampp-windows/27754990#27754990 – Maytham Fahmi Sep 14 '17 at 20:43
  • For XAMPP v3.3.0 here is the vhost configurations https://gist.github.com/aryashreep/623d0acfadd0e37768c18819e462abc2 – Aryashree Pritikrishna Oct 10 '22 at 17:08

7 Answers7

21

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

SuperJumpBros
  • 193
  • 2
  • 15
Atiqur
  • 3,802
  • 1
  • 25
  • 26
  • 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 Jul 25 '16 at 12:36
  • 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. – Jacob Jewett Jul 25 '16 at 12:37
  • 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. – Atiqur Jul 25 '16 at 14:09
  • Refused to connect – Jacob Jewett Jul 26 '16 at 04:10
  • 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. – Atiqur Jul 26 '16 at 05:13
  • ok disabled everything and tryed it...nothing; also updated the vhosts – Jacob Jewett Jul 26 '16 at 07:10
  • does anyone have a solution? – Jacob Jewett Jul 30 '16 at 13:29
  • @Atiqur, bro could you please take a look at my question https://stackoverflow.com/questions/45173872/virtual-host-cannot-create-with-xampp-server ? – May Phyu Jul 18 '17 at 17:58
  • @MayPhyu Sure . – Atiqur Jul 19 '17 at 12:39
  • thanks, I had an issue like this but by me just the ` ServerName localhost DocumentRoot "C:\xampp\htdocs" ` part was missing, and I do not know your `Apache` version, but for me the ` DirectoryIndex index.php ` part was not required. – Top-Master May 18 '19 at 07:20
4

Additionally make sure that the line

Include etc/extra/httpd-vhosts.conf

is not quoted out in httpd.conf

shizhen
  • 12,251
  • 9
  • 52
  • 88
Tom
  • 281
  • 4
  • 7
0

The answer I found that works is to to this in the hosts file.

192.168.0.47        localhost somthing.instancegaming.net      
Jacob Jewett
  • 349
  • 2
  • 4
  • 18
0

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.

Artorias2718
  • 575
  • 5
  • 11
0

I have similar issue, vhosts not working. But in my case I found there was the permission issue with host file. Hope this helps for some one. hosts file ignored, how to troubleshoot?

Bikash Waiba
  • 160
  • 3
  • 11
0

If pings are successful but a Virtual Host is not working with XAMPP 7.3.1 and Windows 10 Pro the problem may be interference with the World Wide Web Publishing Service.

On my system, Apache and MySQL start successfully but the virtual host cannot be browsed till I stop the WWWPS service (in Windows Services). The virtual host then becomes instantly available. It instantly stops working when the WWWPS is started again.

wightowl
  • 1
  • 1
0

I fixed the problem by just restarting my computer after setting up the System32 file hosts and the apache vhosts.