2013-03-14 73 views
2

大家好,我是Zend Framework的新手,顯然完全無法使其工作。Zend Framework 2:嘗試訪問本地主機時出現禁止錯誤

當我嘗試訪問本地主機時,瀏覽器在我處拋出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 zend的應用程序文件夾內的公共目錄/ www/html等/ ZF2教程/:

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 

最後我也FileInfo的上httpd.conf中,以允許htaccess的閱讀設置。

那麼,這裏發生了什麼?謝謝!

更新:我張貼的/ var文件列表/ www/html等/ ZF2教程/公共文件夾與他們的權限:

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 
+0

你能編輯您的問題,包括'LS -al在/ var/www/html等/ ZF2教程/ public'的輸出? – 2013-03-14 11:47:42

+0

你有它。gerard是我的用戶名(我將公共文件夾的所有者更改爲我的帳戶,以檢查是否有問題) – 2013-03-14 13:05:37

回答

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(); 

有什麼想法發生了什麼?謝謝!

0

你確定你的Apache服務器運行正常嗎? 如果Apache服務器宕機的PHP文件不能被執行,並顯示爲文本

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
在虛擬主機設置

確保您已經添加

 Require all granted 

而且還確保您的DocumentRoot路徑是正確的,並且您已經包括像這樣的XAMPP用戶:

的DocumentRoot「C:/ XAMPP/htdocs中/ ZF2教程/公衆」

,使訪問

相關問題