如何在 Xampp 上为 Laravel 启用虚拟主机?
How to enable Virtual Host on Xampp for Laravel?
我在 Windows 7 Pro 上有 XAMPP 运行。我正在尝试设置一个虚拟主机,这样当我使用 "dev.app" 作为域时,我可以直接进入 laravel 安装的 public 文件夹。
Laravel 位于 F:/xampp/htdocs/dev/public
我打开了位于 F:\xamp\apache\conf\extra\https-vhosts.conf
的 httpd-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
的 hosts 文件并添加更改 localhost 行看起来像这样
127.0.0.1 localhost dev.app
127.0.0.1 127.0.0.1
但是,当我在浏览器中转到 dev.app 时,出现此错误
Unable to connect
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.
我在这里错过了什么?
我做错了什么?
注意:我在更改 vhosts 文件后重新启动了 Apache。另外,我更新了 laravel 配置文件夹中的 app.php 文件,在 url.
中有 http://dev.app
值
已更新
添加 http://.... 后,网站解析但图像未显示。
hosts 文件应该如下所示,这样才能在 IPV4 和 IPV6 网络上找到它
127.0.0.1 localhost dev.app
::1 localhost dev.app
如果您使用的是 Apache 2.4.x httpd-vhosts.conf
中的这一行
NameVirtualHost *:80
Apache 2.4 不再需要或不允许。
vhost 文件应如下所示,您混合了 Apache 2.2 和 2.4 语法,虽然只要激活了 mod_access_compat
就允许使用任何一个,但您不应混合使用它们,2.4 语法更好。您还错过了其他一些有用的点点滴滴
<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>
使用 laragon 服务器代替 XAMPP。 Laragon 的一个有用功能是自动虚拟主机。
详细了解 Laragon 的漂亮 URL here
`打开C:\xampp\apache\conf\httpd.conf,定位到
虚拟主机
#include conf/extra/httpd-vhosts.conf,去掉这一行的#,
保存存档,
重启服务器`
我在 Windows 7 Pro 上有 XAMPP 运行。我正在尝试设置一个虚拟主机,这样当我使用 "dev.app" 作为域时,我可以直接进入 laravel 安装的 public 文件夹。
Laravel 位于 F:/xampp/htdocs/dev/public
我打开了位于 F:\xamp\apache\conf\extra\https-vhosts.conf
httpd-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
的 hosts 文件并添加更改 localhost 行看起来像这样
127.0.0.1 localhost dev.app
127.0.0.1 127.0.0.1
但是,当我在浏览器中转到 dev.app 时,出现此错误
Unable to connect
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.
我在这里错过了什么? 我做错了什么?
注意:我在更改 vhosts 文件后重新启动了 Apache。另外,我更新了 laravel 配置文件夹中的 app.php 文件,在 url.
中有http://dev.app
值
已更新 添加 http://.... 后,网站解析但图像未显示。
hosts 文件应该如下所示,这样才能在 IPV4 和 IPV6 网络上找到它
127.0.0.1 localhost dev.app
::1 localhost dev.app
如果您使用的是 Apache 2.4.x httpd-vhosts.conf
中的这一行NameVirtualHost *:80
Apache 2.4 不再需要或不允许。
vhost 文件应如下所示,您混合了 Apache 2.2 和 2.4 语法,虽然只要激活了 mod_access_compat
就允许使用任何一个,但您不应混合使用它们,2.4 语法更好。您还错过了其他一些有用的点点滴滴
<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>
使用 laragon 服务器代替 XAMPP。 Laragon 的一个有用功能是自动虚拟主机。 详细了解 Laragon 的漂亮 URL here
`打开C:\xampp\apache\conf\httpd.conf,定位到
虚拟主机
#include conf/extra/httpd-vhosts.conf,去掉这一行的#, 保存存档, 重启服务器`