2013-08-17 106 views
0

我在共享HostGator服務器上部署了Laravel 4應用程序。Laravel 4 HostGator上的內部服務器錯誤500

當我瀏覽到:

http://mydomain.com/laravel/public/ 

我可以看到Laravel閃屏。

但是當我嘗試訪問任何其他途徑,比如,/用戶/或帖子我越來越

Internal Server Error 500 

http://mydomain.com/laravel/public/posts 

控制器:

public function index() 
    { 
     $posts = $this->post->all(); 

     return View::make('posts.index', compact('posts')); 
    } 

在routes.php文件:

Route::resource('posts', 'PostsController'); 

我使用Jeffrey Way的Generator來支撐職位實體。

同樣在我的本地機器上正常工作。控制器不包含任何邏輯,它們只輸出提取的數據。

錯誤日誌爲空。

任何想法要檢查什麼? .htaccess,也許? 這裏是我有:

AddType application/x-httpd-php53 .php 
<IfModule mod_rewrite.c> 
    Options -MultiViews 
    RewriteEngine On 

    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^index.php [L] 
</IfModule> 
+0

沒有服務器日誌的500錯誤肯定是.htaccess。它也可能會丟失諸如PDO或mcrypt之類的php擴展(通常只有隱藏纔會出現這種情況)如果php抑制錯誤 - 我不認爲Laravel會這樣做)。嘗試將index.php文件添加到URL中,然後刪除您的htaccess文件以測試htaccess文件是否是問題。 – fideloper

+0

你是對的@fideloper,刪除一切從的.htaccess除非該指令使用PHP 5.3,使應用程序的工作: 將AddType應用/的X的httpd-php53 .PHP 當然,現在的URL必須包括的index.php 在我的情況:mydomain.com/laravel/public/index.php/posts 所以,現在我知道.htaccess導致的問題,任何人都可以提出修復它? –

+0

我在這裏找到了解決方案:http://stackoverflow.com/a/16116678/385402 –

回答

9

正如評論所說,沒有從應用程序記錄相應的日誌文件條目500錯誤可能是.htaccess文件的問題。

由於OP中發現的問題與重寫(而不是指令使用PHP 5.3):

因爲這可能是在HostGator的一個共同的問題,您應該在他們的幫助文檔檢查。

然而,我在修復首次嘗試將添加一個RewriteBase指令:

RewriteBase/

因此,它看起來像:

<IfModule mod_rewrite.c> 
    Options -MultiViews 
    RewriteEngine On 
    RewriteBase/

    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^index.php [L] 
</IfModule> 

注意,這裏假設你正在運行的網絡應用程序形成web根目錄而不是子目錄。

+0

如果它在一個子目錄中,如:public_html/domain.com/laravel?如果你已經使用過它,那麼如果你知道RewriteBase指令應該放在你的頭腦之上,那麼它將會非常有用。 –

+1

'RewriteBase/laravel' - 基本上,無論子文件夾是什麼。如果您通過「example.com/laravel」和「RewriteBase/laravel」訪問網站。如果您通過「example.com/some/folders/laravel」然後「RewriteBase/some/folders/laravel」訪問它。 – fideloper

+0

這對我來說很有效,因爲我沒有在我的'vhost'文件中授權'AllowOverride All'。這阻止了'htaccess'文件中的重寫。 – h4k1m