我希望codeigniter回显php错误,而不是500个内部错误

时间:2022-10-28 10:52:17

I have currently set my Codeigniter root index.php's environment variable to development.

我现在已经设置了Codeigniter根索引。php的环境变量。

And I haven't also enabled tiny URL mode.

我还没有启用小URL模式。

I don't like to check /var/log/apache2/error.log every night and day!

我不喜欢检查/var/log/apache2/error。日日夜夜的记录!

Want my PHP errors back to the page. 500 Internal error is really the *HARD*est method that can be used to show the error.

希望PHP错误返回页面。500个内部错误实际上是可以用来显示错误的最硬的方法。

Note that we are working on an Ubuntu 12.04 LTS server with default config.

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

3 个解决方案

#1


13  

As mentioned in the comment I'm doubtful that this is CodeIgniter's issue. It's more likely that you simply have display_errors set to off in your php.ini.

正如在评论中提到的,我怀疑这是不是CodeIgniter的问题。在php.ini中,更有可能只是将display_errors设置为off。

If I remember correctly, CI's index.php contains a call to ini_set('error_reporting', ..); to change the default behaviour anyway, so you could always look in there first and see what's going on.

如果我没记错的话,是CI索引。php包含对ini_set('error_reporting', .. .)的调用;为了改变默认的行为,你可以先看看里面发生了什么。

Just had a look, here's the default:

看一下,这里是默认值:

/*
|---------------------------------------------------------------
| 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);

If you simply add under there ini_set('display_errors', 1);, it should start working just fine. Obviously the best bet would be to add a switch for your environment to set these variables, I'm not sure why it's not like that already, but here's an example:

如果您只是在那里添加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;
    }
}

#2


3  

Just add the following in your index.php, in the development environment case:

只需在索引中添加以下内容。php,在开发环境中:

case 'development':
 error_reporting(E_ALL);
 ini_set('display_errors', 'On');

EDIT: as Rudi Visser said, you could fix it changing your php.ini. I prefer to fix it here, so whenever I download the project (my laptop, my office pc or a computer I borrow in an emergency, I don't need to change the php.ini configuration)

编辑:正如Rudi Visser所说,你可以修改你的ph .ini。我更喜欢在这里修改它,所以每当我下载项目(我的笔记本电脑,我的办公电脑或者我在紧急情况下借来的电脑)时,我都不需要修改php。ini配置)

#3


0  

I had the same problem the only thing i got from codeigniter was only an 500 Internal error.(my old projects and a clean install did the same) But the interesting part is that my non CI projects still worked that contained mostly php.

我也有同样的问题我从codeigniter得到的唯一结果就是500个内部错误。(我以前的项目和干净的安装都是一样的)但有趣的是,我的非CI项目仍然在运行,主要包含php。

The tip to write out the error with

要写出错误的提示。

ini_set('display_errors', 'On' / ,1)

Solved my problem for some reason i didn't have the rights to read the codeigniter core files.

由于某些原因,我解决了我的问题,我没有权利阅读codeigniter核心文件。

Adding ' +r ' to the files fixed the problem.

在文件中添加“+r”解决了这个问题。

Rudi Visser
CarlosIPe
I Thank you both for the solution.

谢谢你们的解决方案。

#1


13  

As mentioned in the comment I'm doubtful that this is CodeIgniter's issue. It's more likely that you simply have display_errors set to off in your php.ini.

正如在评论中提到的,我怀疑这是不是CodeIgniter的问题。在php.ini中,更有可能只是将display_errors设置为off。

If I remember correctly, CI's index.php contains a call to ini_set('error_reporting', ..); to change the default behaviour anyway, so you could always look in there first and see what's going on.

如果我没记错的话,是CI索引。php包含对ini_set('error_reporting', .. .)的调用;为了改变默认的行为,你可以先看看里面发生了什么。

Just had a look, here's the default:

看一下,这里是默认值:

/*
|---------------------------------------------------------------
| 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);

If you simply add under there ini_set('display_errors', 1);, it should start working just fine. Obviously the best bet would be to add a switch for your environment to set these variables, I'm not sure why it's not like that already, but here's an example:

如果您只是在那里添加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;
    }
}

#2


3  

Just add the following in your index.php, in the development environment case:

只需在索引中添加以下内容。php,在开发环境中:

case 'development':
 error_reporting(E_ALL);
 ini_set('display_errors', 'On');

EDIT: as Rudi Visser said, you could fix it changing your php.ini. I prefer to fix it here, so whenever I download the project (my laptop, my office pc or a computer I borrow in an emergency, I don't need to change the php.ini configuration)

编辑:正如Rudi Visser所说,你可以修改你的ph .ini。我更喜欢在这里修改它,所以每当我下载项目(我的笔记本电脑,我的办公电脑或者我在紧急情况下借来的电脑)时,我都不需要修改php。ini配置)

#3


0  

I had the same problem the only thing i got from codeigniter was only an 500 Internal error.(my old projects and a clean install did the same) But the interesting part is that my non CI projects still worked that contained mostly php.

我也有同样的问题我从codeigniter得到的唯一结果就是500个内部错误。(我以前的项目和干净的安装都是一样的)但有趣的是,我的非CI项目仍然在运行,主要包含php。

The tip to write out the error with

要写出错误的提示。

ini_set('display_errors', 'On' / ,1)

Solved my problem for some reason i didn't have the rights to read the codeigniter core files.

由于某些原因,我解决了我的问题,我没有权利阅读codeigniter核心文件。

Adding ' +r ' to the files fixed the problem.

在文件中添加“+r”解决了这个问题。

Rudi Visser
CarlosIPe
I Thank you both for the solution.

谢谢你们的解决方案。