【问题标题】:Laravel 4 Internal Server Error 500 on HostgatorHostgator 上的 Laravel 4 内部服务器错误 500
【发布时间】:2013-08-17 22:38:10
【问题描述】:

我在共享 Hostgator 服务器上部署了一个 Laravel 4 应用程序。

当我导航到:

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

我可以看到 Laravel 启动画面。

但是当我尝试访问到 /users 或 /posts 的任何其他路由时,我得到了

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 的生成器来搭建帖子实体。

在我的本地机器上也可以正常工作。控制器不包含任何逻辑,它们只输出获取的数据。

错误日志为空。

有什么想法可以检查吗? .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>

【问题讨论】:

  • 500 没有服务器日志的错误肯定是 .htaccess。它也可能缺少诸如 PDO 或 mcrypt 之类的 php 扩展(这不太可能,因为通常只隐藏如果 php 抑制错误 - 我不认为 Laravel 会这样做)。尝试将 index.php 文件添加到 URL,并删除您的 htaccess 文件以测试 htaccess 文件是否是问题。
  • 你是对的@fideloper,从 .htaccess 中删除所有内容,除了使用 PHP 5.3 的指令使应用程序工作:AddType application/x-httpd-php53 .php 当然,现在的 URL 必须包含索引.php 在我的情况下:mydomain.com/laravel/public/index.php/posts 现在我知道 .htaccess 导致了这个问题,任何人都可以建议修复它吗?
  • 我在这里找到了解决方案:stackoverflow.com/a/16116678/385402

标签: .htaccess laravel laravel-4 internal-server-error


【解决方案1】:

如 cmets 中所述,应用程序记录器中没有相应日志文件条目的 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 根目录而不是子目录运行 Web 应用程序。

【讨论】:

  • 如果它位于子目录中,例如: public_html/domain.com/laravel 怎么办?如果您之前使用过它,那么如果您知道 RewriteBase 指令应该是您的首要任务,那将会非常有帮助。
  • RewriteBase /laravel - 基本上,无论子文件夹是什么。如果您通过“example.com/laravel”访问该站点,那么RewriteBase /laravel。如果您通过“example.com/some/folders/laravel”访问它,那么RewriteBase /some/folders/laravel
  • 这对我有用,因为我没有在我的 vhost 文件中授权 AllowOverride All。这阻止了htaccess 文件内部的重写。
  • 我找到了答案:stackoverflow.com/a/16116678/385402。谢谢大家
  • 在 Rackspace Cloudsites 上遇到了同样的问题,RewriteBase / 修复了它。
猜你喜欢
  • 2016-02-12
  • 1970-01-01
  • 2015-01-05
  • 2016-04-08
  • 1970-01-01
  • 2014-10-25
  • 2015-08-12
  • 1970-01-01
  • 2017-04-12
相关资源
最近更新 更多