Xampp vhosts do not work

2019-08-05 02:11发布

I have trouble with xampp. Having installed it, my virtual hosts do not want to work at all. When i am trying to access http://localhost/ - works good. But if i type something else, like http://laravel.dev it gives me an error.

hosts

# Copyright (c) 1993-2009 Microsoft Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host
# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost


127.0.0.1       localhost
127.0.0.1       laravel.dev

Virtual Hosts

# 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>
    ##ServerAdmin webmaster@dummy-host.example.com
    ##DocumentRoot "C:/xampp2/htdocs/dummy-host.example.com"
    ##ServerName dummy-host.example.com
    ##ServerAlias www.dummy-host.example.com
    ##ErrorLog "logs/dummy-host.example.com-error.log"
    ##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>

##<VirtualHost *:80>
    ##ServerAdmin webmaster@dummy-host2.example.com
    ##DocumentRoot "C:/xampp2/htdocs/dummy-host2.example.com"
       ##ServerName dummy-host2.example.com
    ##ErrorLog "logs/dummy-host2.example.com-error.log"
    ##CustomLog "logs/dummy-host2.example.com-access.log" common
##</VirtualHost>


<VirtualHost *:80>
    DocumentRoot "C:/xampp2/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/xampp2/sites/laravel.dev/www"
    ServerName laravel.dev
</VirtualHost>

Thanks!

2条回答
孤傲高冷的网名
2楼-- · 2019-08-05 02:27

Exactly what kind of Error do you see?

There could be a problem if you don't specify a correct along your Vhost. Try to adapt your second vhosts to something like:

<VirtualHost *:80>
    ServerName laravel.dev
    DocumentRoot "C:/xampp2/sites/laravel.dev/www"
    SetEnv APPLICATION_ENV "development"
    <Directory "C:/xampp2/sites/laravel.dev/www">
        DirectoryIndex index.php   ## Edit this to your needs, e.g. index.html
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Also, I encountered some problems using absolute paths, try to use relative paths (e.g. "sites/laravel.dev/www") and check if that makes a difference.

查看更多
时光不老,我们不散
3楼-- · 2019-08-05 02:41

I had the same problem when I first started to use XAMPP. It was really hard to find answer online, so I have started to experiment myself. The solution that worked for me was to clear the browser cache. :) Yes that was simple as this ...

For those who do not know:

hosts file can be found in C:\Windows\System32\drivers\etc directory and

httpd-vhost.conf can be found in C:\xampp\apache\conf\extra directory

Ps. here you go - my working configuration. (Don't forget to clear your browser cache after you have made the changes to those files and restart your Apache server in your xampp panel) Note that to edit hosts file you have to run the editing program such as Notepad++ as administrator. If you don't do it your editing program will not be able make any changes to that file.*

hosts

127.0.0.1  symfony.dev
127.0.0.1  symfony

httpd-vhost.conf

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@symfony.com
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
    ServerAlias 127.0.0.1
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@symfony.com
    DocumentRoot "C:/xampp/htdocs/www/_DoNotTouch_Symfony2/path/web"
    ServerName symfony.dev
</VirtualHost>

One more little thing... When you run your virtual server in the browser make sure that you will use http:// before the server name (at last at the first time you will call it). So run:

http://symfony.dev

after that you will be able to use only

symfony.dev

(That how it works in a Google Chrome browser anyway)

Thumbs up if I have helped to solve your issue ;-).

Kind Regards

查看更多
登录 后发表回答