【问题标题】:Apache Virtual Host, access forbidden. Using XAMPP OS XApache 虚拟主机,禁止访问。使用 XAMPP OS X
【发布时间】:2016-08-05 00:16:41
【问题描述】:

我在浏览器中转到“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 目录中没有 hosts 文件。

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

...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/

【问题讨论】:

  • 你能打mytest.dev/index.php吗?
  • 不,我无法收到相同的消息,但我认为我制造了一个问题,很可能是 sudo chmod 644 /Applications/XAMPP/xamppfiles/htdocs/ 现在我什至不能cd 进入我的 htdocs 目录.. 我也遇到了访问 localhost/rockpaperscissors 的问题(另一个放在我的 htdocs 中的应用程序,它在深夜运行良好)

标签: php macos apache xampp virtualhost


【解决方案1】:

所有来自根目录的目录都必须是可执行的,您或 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 /

然后确保您的网络文件是可读和可执行的

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

【讨论】:

    猜你喜欢
    • 2021-04-05
    • 2012-02-11
    • 2020-12-17
    • 2011-09-13
    • 2015-09-16
    • 2019-10-01
    • 2015-09-16
    • 2012-12-28
    相关资源
    最近更新 更多