Zend Framework 2:403尝试访问localhost时出现禁止错误

时间:2013-03-14 11:31:14

标签: zend-framework2 localhost http-status-code-403

大家好,我是Zend Framework的新手,显然无法让它发挥作用。

当我尝试访问localhost时,浏览器会向我抛出403禁止访问错误。这是我的虚拟主机文件:

  NameVirtualHost *:80
<VirtualHost *:80>
    ServerName zf2-tutorial.localhost
    DocumentRoot /var/www/html/zf2-tutorial/public
    SetEnv APPLICATION_ENV "development"
    <Directory /var/www/html/zf2-tutorial/public>
        Options +Indexes +FollowSymLinks +ExecCGI
    DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

我的htacces文件位于/ var / www / html / zf2-tutorial /上的zend应用程序文件夹中的公共目录中:

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

我对该目录上的所有文件也有775权限。但是,apache error_log似乎不这么认为:

[Thu Mar 14 12:15:48.751980 2013] [core:crit] [pid 5755] (13)Permission denied: [client 127.0.0.1:60849] AH00529: /var/www/html/zf2-tutorial/public/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/var/www/html/zf2-tutorial/public/' is executable

最后我还在httpd.conf上设置了FileInfo,以便允许htaccess读取。

那么,这里发生了什么的任何线索?谢谢!

更新:我发布了/ var / www / html / zf2-tutorial / public文件夹的文件列表及其权限:

total 28
drwxrwxr-x. 5 gerard root 4096 mar 14 14:01 .
drwxr-xr-x. 7 gerard root 4096 mar 14 11:20 ..
drwxrwxr-x. 2 gerard root 4096 ene 31 17:19 css
-rwxrwxr-x. 1 gerard root  711 mar 14 12:25 .htaccess
drwxrwxr-x. 2 gerard root 4096 ene 31 17:19 images
-rwxrwxr-x. 1 gerard root  303 ene 31 17:19 index.php
drwxrwxr-x. 2 gerard root 4096 ene 31 17:19 js

4 个答案:

答案 0 :(得分:3)

使用EasyPHP DevServ 14时遇到了同样的问题。

问题来自httpd.conf文件中缺少的一行

要求全部授予

<Directory "PATH TO YOUR DIR">
    Options FollowSymLinks Indexes
    AllowOverride All
    Order deny,allow
    Allow from any
    Deny from none
    Require all granted
</Directory>

希望它有所帮助!

答案 1 :(得分:1)

虚拟主机设置中的

确保您已添加

     Require all granted

还要确保您的DocumentRoot路径正确,并为Xampp用户提供了类似的内容:

DocumentRoot“C:/ xampp / htdocs / zf2-tutorial / public”

启用访问权限

答案 2 :(得分:0)

好的问题解决了!这是SELinux禁止访问这些文件所以我只是做了它建议我在bash上做的事情:

1. /sbin/restorecon -v /var/www/html/zf2-tutorial/public/.htaccess 
2. setsebool -P httpd_read_user_content 1

但现在我有一个更严重的问题!浏览器显示“literaly”index.php的内容,而不是加载脚本本身。浏览器窗口只是将其显示为文本:

    <?php
/**
 * This makes our life easier when dealing with paths. Everything is relative
 * to the application root now.
 */
chdir(dirname(__DIR__));

// Setup autoloading
require 'init_autoloader.php';

// Run the application!
Zend\Mvc\Application::init(require 'config/application.config.php')->run();

知道发生了什么事吗?谢谢!

答案 3 :(得分:0)

您确定您的Apache服务器运行正常吗? 如果apache服务器关闭,php文件将无法执行并显示为文本