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

时间:2016-04-13 18:07:34

标签: php macos apache xampp virtualhost

我在浏览器中转到“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文件中,我有以下UN-comment评论行,我的指令看起来像这样:

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

但是,上面的行是在/ Applications / XAMPP / etc中的根/ 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/

1 个答案:

答案 0 :(得分:3)

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