简体   繁体   English

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

[英]I want codeigniter to echo php errors instead of 500 internal error

I have currently set my Codeigniter root index.php 's environment variable to development . 我目前已将我的Codeigniter根index.phpenvironment变量设置为development

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.log

Want my PHP errors back to the page. 希望我的PHP错误回到页面。 500 Internal error is really the *HARD *est method that can be used to show the error. 500内部错误实际上是* HARD * est方法,可用于显示错误。

Note that we are working on an Ubuntu 12.04 LTS server with default config. 请注意,我们正在使用默认配置的Ubuntu 12.04 LTS服务器。

As mentioned in the comment I'm doubtful that this is CodeIgniter's issue. 正如评论中所提到的,我怀疑这是CodeIgniter的问题。 It's more likely that you simply have display_errors set to off in your php.ini . 你更有可能只是在php.ini中将display_errors设置为off。

If I remember correctly, CI's index.php contains a call to ini_set('error_reporting', ..); 如果我没记错的话,CI的index.php包含对ini_set('error_reporting', ..);的调用ini_set('error_reporting', ..); to change the default behaviour anyway, so you could always look in there first and see what's going on. 无论如何要改变默认行为,所以你可以先看看那里然后看看发生了什么。

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); 如果你只是在那里添加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: 显然最好的办法是为你的环境添加一个开关来设置这些变量,我不知道为什么它不是那样的,但这是一个例子:

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;
    }
}

Just add the following in your index.php, in the development environment case: 只需在开发环境案例中的index.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. 编辑:正如Rudi Visser所说,你可以修改它改变你的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) 我更喜欢在这里修复它,所以每当我下载项目时(我的笔记本电脑,办公室电脑或我在紧急情况下借用的电脑,我都不需要更改php.ini配置)

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 CarlosIPe
I Thank you both for the solution. 我感谢你们两个解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM