Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

And I haven't also enabled tiny URL mode.

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

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.

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

like image 361
Mohammad Naji Avatar asked Jan 05 '13 14:01

Mohammad Naji


1 Answers

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.

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.

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:

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;
    }
}
like image 99
Rudi Visser Avatar answered Oct 24 '22 03:10

Rudi Visser