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

查看:54
本文介绍了如何在 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 配置文件夹中的 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天全站免登陆