如何在Xampp上为Laravel启用虚拟主机? [英] How to enable Virtual Host on Xampp for Laravel?

查看:158
本文介绍了如何在Xampp上为Laravel启用虚拟主机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在Windows 7 Pro上运行的XAMPP.我正在尝试设置虚拟主机,以便当我将"dev.app"用作域时,直接进入laravel安装的公共文件夹.

I have XAMPP running on Windows 7 Pro. I am trying to setup a Virtual Host so that when I use "dev.app" as a domain I get directly to my public folder of laravel installation.

Laravel位于F:/xampp/htdocs/dev/public

Laravel is located at F:/xampp/htdocs/dev/public

我打开了位于F:\xamp\apache\conf\extra\https-vhosts.conf

并以此替换所有内容

# 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 localhost>
    DocumentRoot "F:/xampp/htdocs/"
    ServerAdmin admin@localhost

    <Directory "F:/xampp/htdocs/">
        Options Indexes FollowSymLinks
        AllowOverride all
    </Directory>

</VirtualHost>

# Development
<VirtualHost dev.app>
    DocumentRoot "F:/xampp/htdocs/dev/public"
    ServerAdmin admin@localhost

    <Directory "F:/xampp/htdocs/dev/public">
       AllowOverride All
       Order Allow,Deny
       Allow from all
       Require all granted
    </Directory>
</VirtualHost>

然后我打开位于C:\Windows\System32\drivers\etc的主机文件,并添加了更改localhost行的外观,如下所示:

then I opened my hosts file located at C:\Windows\System32\drivers\etc and added changed the localhost line to look like this

127.0.0.1       localhost      dev.app
127.0.0.1       127.0.0.1

但是,当我在浏览器中转到dev.app时,会出现此错误

However, when I go to dev.app in my browser I get this error

无法连接

Firefox无法通过app.dev建立与服务器的连接.

Firefox can't establish a connection to the server at app.dev.

The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer's network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.

我在这里想念什么? 我做错了什么?

What am I missing here? What did I do wrong?

注意::更改vhosts文件后,我重新启动了Apache.另外,我更新了laravel的config文件夹中的app.php文件,使其在URL中具有http://dev.app值.

Note: I restarted Apache after I change the vhosts file. Also, I updated the app.php file in the config folder of laravel to have http://dev.app value in the url.

已更新 添加http://....后,网站解析了,但图像没有显示.

UPDATED after adding http://.... the site resolve but the images are not showing.

推荐答案

hosts文件应如下所示,以便可以在IPV4和IPV6网络上找到它

The hosts file should look like this so that it can be found on the IPV4 and IPV6 networks

127.0.0.1  localhost dev.app
::1        localhost dev.app

如果您使用的是Apache 2.4.x,则httpd-vhosts.conf中的这一行

If you are using Apache 2.4.x this line in httpd-vhosts.conf

NameVirtualHost *:80

不再是Apache 2.4所必需或允许的.

is no longer required or allowed for Apache 2.4.

vhost文件应如下所示,混合了Apache 2.2和2.4语法,并且只要激活了mod_access_compat,就可以允许使用两者,但不要混合使用它们,并且2.4语法更好.您还错过了一些其他有用的点点滴滴

The vhost file should look like this, you mixed Apache 2.2 and 2.4 syntax and while either is allowed as long as you have mod_access_compat activated, you should not mix them and the 2.4 syntax is better. You also missed a few other useful bits and pieces

<VirtualHost *:80>
    DocumentRoot "F:/xampp/htdocs/"
    ServerAdmin admin@localhost
    ServerName localhost

    <Directory "F:/xampp/htdocs/">
       Options Indexes FollowSymLinks
       AllowOverride all
       Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "F:/xampp/htdocs/dev/public"
    ServerAdmin admin@localhost
    ServerName dev.app
    ServerAlias www.dev.app

    <Directory "F:/xampp/htdocs/dev/public">
       AllowOverride All
       Options Indexes FollowSymLinks

       Require local
       # if you want access from other pc's on your local network
       #Require ip 192.168.1
       # Only if you want the world to see your site
       #Require all granted
    </Directory>
</VirtualHost>

这篇关于如何在Xampp上为Laravel启用虚拟主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆