[Php] Codeigniter displays a blank page instead of error messages



Answers

Make sure php5-mysql is installed.

Question

I'm using Codeigniter, and instead of error messages I'm just getting a blank page. Is there any way to show PHP error messages instead? It's very hard to debug when I get no feedback.

My environment is Ubuntu with Apache.




If you're using CI 2.0 or newer, you could change ENVIRONMENT type in your index.php to define('ENVIRONMENT', 'testing');.
Alternatively, you could add php_flag display_errors on to your .htaccess file.




This happens to me whenever I do autoload stuff in autoload.php like the 'database'

To resolve this, If you're using Windows OS

  1. Open your php.ini. Search and uncomment this line - extension=php_mysql.dll

    (Please also check If the PHP directive points to where your extensions is located.
    Mine is extension_dir = "C:\php-5.4.8-Win32-VC9-x86\ext")

  2. Restart Apache and refresh your page




This behavior occurs when you have basic php syntax error in your code. In case when you have syntax errors the php parser does not parse the code completely and didnot display anything so all of the above suggestion would work only if you have other than syntax errors.




Codeigniter doesn't seem to throw an error message when I was referencing a view that did not exist.

In my example I had within my controller:

$this->load->view('/admin/index/access_controls/groups/add');

Because the file did not exist, I got a blank "An error has occurred page". I changed the code to:

$this->load->view('/admin/access_controls/groups/add');

This was how I resolved the same issue you seem to be having, hope this helps someone some day.




check if error_reporting is ON at server or not, if that id off you wont get any errors and just blank page. if you are on a shared server then you can enable error reporting via htaccess. In codeIgniter add following in your htaccess

php_flag display_errors On

and set

error_reporting(E_ERROR); ## or what ever setting desired in php

hope it will work for you




Are you using the @ symbol anywhere?

If you have something like:

@include('page_with_error.php');

You will get a blank page.




Try adding this to your index.php file

error_reporting(E_ALL);



If you have this in your php.ini:

display_error = On;

and you have this in your CI Application at the same time

error_reporting(0);

you'll get HTTP/1.1 200 OK and a completely bank page.

That's because when display_error is on, the php-fpm always return HTTP code 200. And all the errors to output are forbidden by error_reporting(0).

For CI application,the entry index.php sets up the running environment as bellows:

if(isset($_SERVER['SERVER_ENV'])) {
    define('ENVIRONMENT', $_SERVER['SERVER_ENV']);
} else {
    define('ENVIRONMENT', 'development');
}

if (defined('ENVIRONMENT'))
{
    switch (ENVIRONMENT)
    {
        case 'development':
            error_reporting(E_ALL);
            ini_set('display_errors', 1);
        break;

        case 'testing':
        case 'production':
            error_reporting(0);
        break;

        default:
            exit('The application environment is not set correctly.');
    }
}

In short, when you set ENV directive in your webserver's conf,say Nginx's fastcgi_params:

fastcgi_param  SERVER_ENV         production;

then CI will automatically set

error_reporting(0);



Often when codeigniter displays nothing, there is a syntax error. Mostly if the app was running seamlessly previously, just look around your most recent edits. For me the experience this time was the entire app, not just a page. So I did a quick brain scan for the most recent edits I had done and worked backwards, reviewing each file I had worked on this day. Turned out to be some 'where' clauses in two model files: For instance, I had

$this->db->where('Type' => 'Blog'); rather than $this->db->where('Type', 'Blog');



Links