Apache 虚拟主机,禁止访问。使用 XAMPP OS X

Apache Virtual Host, access forbidden. Using XAMPP OS X

我在浏览器中转到 "mytest.dev",出现以下错误:

Access forbidden!

You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.

If you think this is a server error, please contact the webmaster.

Error 403

mytest.dev
Apache/2.4.18 (Unix) OpenSSL/1.0.2g PHP/5.6.19 mod_perl/2.0.8-dev Perl/v5.16.3

在我的 /Applications/XAMPP/etc/httpd.conf 文件中,我有以下未注释的行,我的指令看起来像这样:

Include etc/extra/httpd-vhosts.conf

DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/trunk/mod/core.html#options
    # for more information.
    #
    #Options Indexes FollowSymLinks
    # XAMPP
    Options Indexes FollowSymLinks ExecCGI Includes

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    #AllowOverride None
    # since XAMPP 1.4:
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

我的 /Applications/XAMPP/etc/extra/httpd-vhosts.conf 我的虚拟主机如下所示:

<VirtualHost *:80>
       DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/myTest"
       ServerName mytest.dev
</VirtualHost>

我的 /etc/hosts 文件中有这个:

127.0.0.1       mytest.dev

然而,以上行在根 /etc 中,而不是在 /Applications/XAMPP/etc 中。我的 /Xampp/etc 目录中没有主机文件。

最后,因为指令中的 DocumentRoot 是这样的:“/Applications/XAMPP/xamppfiles/htdocs/myTest” 我在 myTest 目录中有一个 index.php 文件,里面有一个 hello world 脚本:

...html stuff...
<?php echo '<p>Hello World</p>'; ?>
... html stuff...

我在错误日志中没有得到任何与我的问题密切相关的信息。我查看了 access_log、error_log 和 php_error_log,但找不到与我对 mytest.dev

的请求类似的内容

我还使用以下命令更改了 htdocs 的权限:

sudo chmod 644 /Applications/XAMPP/xamppfiles/htdocs/

根目录中的所有目录必须对您或 Web 服务器可执行,以便能够在读取它们之前遍历它们。以下命令应设置正确的权限:

sudo chmod +X /Applications/XAMPP/xamppfiles/htdocs
sudo chmod +X /Applications/XAMPP/xamppfiles
sudo chmod +X /Applications/XAMPP
sudo chmod +X /Applications
sudo chmod +X /

然后确保您的 Web 文件可读且可执行

sudo chmod -R +Xr /Applications/XAMPP/xamppfiles/htdocs/myTest