Codeigniter 3.x 出现 Heroku 500 错误

Codeigniter 3.x with Heroku 500 error

我在尝试启动暂存 Codeigniter 3.x 项目(第一次)时在 Heroku 中遇到 500 错误。我似乎找不到比这更好的日志了。

我正在使用 heroku-php-apache2 buildpack。 PHP 版本为 5.6.x

但是,通过调试我可以看到它正确地将根目录设置为 public_html,它正在加载根目录中的 index.php,它正在加载 config.php 和database.php,它正在加载 routes.php。

在我的 routes.php 我有: $路线['default_controller'] = "home";

当我转到主页时,出现 500 错误,它没有像预期的那样加载 home/index 控制器方法。当我引用 css 文件时,例如 https://staging-app/css/grid.css,它确实会加载该文件,因此我知道目录正在被正确访问。

如果需要,我的 .htaccess 是

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  #Checks to see if the user is attempting to access a valid file,
  #such as an image or css document, if this isn't true it sends the
  #request to index.php
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  #RewriteCond %{REQUEST_URI} !business-loan-tips.*
  RewriteRule ^(.*)$ index.php?/ [L]
 </IfModule>

  <IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
  </IfModule> 

尽管如此,不管有没有它似乎加载都一样。

我的 composer.json 除“{}”外是空的

我的 Procfile 只有:

web: vendor/bin/heroku-php-apache2 public_html/

关于我可能在哪里出错以获取 500 错误或如何更好地追踪它的任何想法?

编辑: 我确实正确地访问了数据库。我只是无法让我的控制器击中。

使用这个 htaccess 规则

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine on
  RewriteBase /

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

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 

我想你可以编辑你的服务器配置文件。如果服务器是 httpd,则编辑 httpd.conf 文件并使用以下代码启用 htaccess

<Directory /var/www/html/>
    #Options Indexes FollowSymLinks
    AllowOverride All
    #Order allow,deny
    #allow from all
#   Require all granted
</Directory>

我遇到这种麻烦的原因是日志记录工作不正常。事实证明,Heroku 的文档对于使用 Codeigniter 3.x 进行日志记录已经过时了。从 CI 2.x 移动到 CI 3.x,他们将 Log.php 从 /libraries 移到 /core,所以 MY_Log.php 文件Heroku 文档给你的那个应该进入 /core,而不是如所述的 /libraries。

一旦我修复了日志记录,错误就非常简单了...我只需要在 config.php:

中设置
$config['sess_save_path'] = sys_get_temp_dir();

这是 3.x 中的新内容,我忽略了它。现在需要它时我把它留空了。

希望这对某人有所帮助。