我想codeigniter回应php错误而不是500内部错误

Moh*_*aji 5 php codeigniter error-reporting

我目前已将Codeigniter root index.phpenvironment变量设置为development.

我还没有启用微小的URL模式.

我不喜欢/var/log/apache2/error.log每天都在检查!

希望我的PHP错误回到页面.500内部错误实际上是*HARD*est方法,可用于显示错误.

请注意,我们正在使用默认配置的Ubuntu 12.04 LTS服务器.

Rud*_*ser 13

正如评论中所提到的,我怀疑这是CodeIgniter的问题.你更有可能只是display_errors设置为关闭php.ini.

如果我没记错的话,CI's index.php包含了一个ini_set('error_reporting', ..);改变默认行为的调用,所以你可以先看看那里然后看看发生了什么.

刚看了一下,这是默认值:

/*
|---------------------------------------------------------------
| PHP ERROR REPORTING LEVEL
|---------------------------------------------------------------
|
| By default CI runs with error reporting set to ALL.  For security
| reasons you are encouraged to change this when your site goes live.
| For more info visit:  http://www.php.net/error_reporting
|
*/
    error_reporting(E_ALL);
Run Code Online (Sandbox Code Playgroud)

如果你只是在那里添加ini_set('display_errors', 1);,它应该开始工作得很好.显然,最好的办法是增加一个开关,你的环境来设置这些变量,我不知道为什么它不喜欢了,但这里有一个例子:

if (defined('ENVIRONMENT'))
{
    switch (ENVIRONMENT)
    {
        case 'development':
            error_reporting(E_ALL);
            ini_set('display_errors', 1);
            break;
        case 'production':
            error_reporting(0);
            ini_set('display_errors', 0);
            break;
    }
}
Run Code Online (Sandbox Code Playgroud)