简体   繁体   中英

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.

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 [ie .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] & slao check there is no other php path in PATH variable.

  2. restart xampp and browse localhost

Additionally make sure that the line

Include etc/extra/httpd-vhosts.conf

is not quoted out in httpd.conf

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.

我发现有效的答案是在主机文件中解决这个问题。

192.168.0.47        localhost somthing.instancegaming.net      

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM