首页 > 解决方案 > Xampp 上的 Laravel 虚拟主机无法正常工作

问题描述

我想在 XAMPP 上使用虚拟主机加载我的 Laravel 5.8 项目。所以这就是我所做的:

我打开C:\Windows\System32\drivers\etc\hosts并放了这个:

#   127.0.0.1       localhost
#   ::1             localhost
    127.0.0.1       local.nanoclub.ir

然后在C:\xampp\apache\conf\extra\httpd-vhosts.conf,我添加了这个:

<VirtualHost local.nanoclub.ir:80>
    DocumentRoot "C:/xampp/htdocs/badges/public"
    ServerName local.nanoclub.ir
    ServerAlias *.local.nanoclub.ir
    SetEnv APPLICATION_ENV "development"
    <Directory "C:/xampp/htdocs/badges/public">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>    
</VirtualHost>

并将其添加到我的项目 public 中.htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

但是现在当我想local.nanoclub.ir在浏览器上运行时,我得到了这个:

在此处输入图像描述

那么这里出了什么问题?我以前可以正确访问它local.nanoclub.ir,但现在它加载了这个屏幕。

如何解决这个问题?

标签: phplaravelapachexamppvirtualhost

解决方案


您需要授予对此目录的访问权限。

您可以在虚拟主机定义或 apache2.conf 中授予此访问权限

在虚拟主机定义中

<VirtualHost local.nanoclub.ir:80>
    DocumentRoot "C:/xampp/htdocs/badges/public"
    ServerName local.nanoclub.ir
    ServerAlias *.local.nanoclub.ir
    SetEnv APPLICATION_ENV "development"
    <Directory "C:/xampp/htdocs/badges/public">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all

        # The missing one
        Require all granted
    </Directory>    
</VirtualHost>

在 apache2.conf

<Directory C:/xampp/htdocs/badges/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

注意:更改配置后不要忘记重新启动 apache。


推荐阅读