【问题标题】:Codeigniter 3.x with Heroku 500 error带有 Heroku 500 错误的 Codeigniter 3.x
【发布时间】:2018-01-30 20:46:29
【问题描述】:

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

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

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

在我的 routes.php 中,我有: $route['default_controller'] = "家";

当我转到主页时,我得到一个 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?/$1 [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 错误或如何更好地跟踪它的任何想法?

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

【问题讨论】:

    标签: php codeigniter heroku http-status-code-500


    【解决方案1】:

    使用这个 htaccess 规则

    <IfModule mod_rewrite.c>
      Options +FollowSymlinks
      RewriteEngine on
      RewriteBase /
    
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ /index.php?/$1 [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> 
    

    【讨论】:

    • 这是一个尝试 FollowSymlinks 的好建议,但不幸的是它对我的情况没有帮助。还是一样的错误。
    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

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

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

      $config['sess_save_path'] = sys_get_temp_dir();
      

      这是 3.x 中的新功能,我忽略了它。现在需要时我将其留空。

      希望这对某人有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-08
        • 2015-10-01
        • 1970-01-01
        • 2017-04-01
        • 2016-07-10
        • 1970-01-01
        相关资源
        最近更新 更多