Codeigniter displays a blank page instead of error messages

PhpCodeigniter

Php Problem Overview


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.

Php Solutions


Solution 1 - Php

Since none of the solutions seem to be working for you so far, try this one:

ini_set('display_errors', 1);

http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors

This explicitly tells PHP to display the errors. Some environments can have this disabled by default.

This is what my environment settings look like in index.php:

/*
 *---------------------------------------------------------------
 * APPLICATION ENVIRONMENT
 *---------------------------------------------------------------
 */
define('ENVIRONMENT', 'development');
/*
 *---------------------------------------------------------------
 * ERROR REPORTING
 *---------------------------------------------------------------
 */
if (defined('ENVIRONMENT'))
{
	switch (ENVIRONMENT)
	{
		case 'development':
			// Report all errors
			error_reporting(E_ALL);

	     	// Display errors in output
			ini_set('display_errors', 1);
		break;
	
		case 'testing':
		case 'production':
			// Report all errors except E_NOTICE
			// This is the default value set in php.ini
			error_reporting(E_ALL ^ E_NOTICE);

			// Don't display errors (they can still be logged)
			ini_set('display_errors', 0);
		break;

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

Solution 2 - Php

Make sure php5-mysql is installed.

Solution 3 - Php

I had this same problem and as Shayan Husaini pointed out, I had an undetected syntax error.

I solved it using the php linter in the terminal:

php -l file.php

You can also use something like this to use the linter in every file in some folder:

find -type f -name "*.php" -exec php -l '{}' \;

And to filter just the ones with errors:

find -type f -name "*.php" -exec php -l '{}' \; | grep '^[^N]'

That should show files with parsing errors and the line where the error is.

Solution 4 - Php

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.

Solution 5 - Php

you can set it in the main index.php

	define('ENVIRONMENT', 'development');
/*
 *---------------------------------------------------------------
 * ERROR REPORTING
 *---------------------------------------------------------------
 *
 * Different environments will require different levels of error reporting.
 * By default development will show errors but testing and live will hide them.
 */

if (defined('ENVIRONMENT'))
{
	switch (ENVIRONMENT)
	{
		case 'development':
			error_reporting(E_ALL);
		break;

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

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

Solution 6 - Php

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

Solution 7 - Php

I had the same problem a couple days ago. My development environment is Win8 and the website was working just fine, but when i uploaded the files to production server (Linux) was displaying a blank page.

Turns out that models and controllers's filenames should start with a uppercase letter.

> The file must be called ‘Blog.php’, with a capital ‘B’. > > Class names must start with an uppercase letter.

In windows environment this wont matter since windows does not differentiate uppercase and lowercase, but in linux environment, the files wont be displayed.

Hope I've helped.

Solution 8 - Php

Try adding this to your index.php file

error_reporting(E_ALL);

Solution 9 - Php

Make sure you don't have a blank index.html file in your root folder. It happens :)

Solution 10 - Php

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.

Solution 11 - Php

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

Solution 12 - Php

First of all you need to give the permission of your Codeigniter folder, It's might be the permission issue and then start your server.

Solution 13 - Php

In your index.php file add the line:

define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');

Solution 14 - Php

In system/core/Common.php there is an exception handler, with a block of code that looks like this:

 // We don't bother with "strict" notices since they tend to fill up
 // the log file with excess information that isn't normally very helpful.
if ($severity == E_STRICT)
{
	return;
}

By removing the if and the return and the incorrect comment, I was able to get an error message, instead of just a blank page. This project isn't using the most recent version of CodeIgniter, hopefully they've fixed this bug by now.

Solution 15 - Php

load your url helper when you create a function eg,

visibility function_name () {

     $this->load->helper('url');
}

the it will show you errors or a view you loaded.

Solution 16 - Php

Are you using the @ symbol anywhere?

If you have something like:

@include('page_with_error.php');

You will get a blank page.

Solution 17 - Php

I ran into this because I had a CLI running via cron as the root user, thus creating log files with root:root. When you tried to navigate to a URI everything would work fine but CI exhibiting the blank page likely because it didn't have write permission to the log file.

Solution 18 - Php

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.

Solution 19 - Php

i was also facing the same problem and tried almost all the things but finally i restarted my server and i found everything started working fine..i don't know how.....i think it was some server side problem that's why my PHP CODE was not giving any error.

Solution 20 - Php

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

Solution 21 - Php

Another method is to see if you've surpassed the error checking in your code by accident. Search all your code for any instance of error_reporting(). If you call it without parameters, it just returns the current level, and is harmless. If you call it with a parameter, such as 0 (zero), it will turn off error reporting.

You can test for this in CodeIgnitor by looking at their core library under ../system/core/Common.php and finding a section that's at about line 615 that looks like:

if (($severity & error_reporting()) !== $severity)
{
   return;
} 

Add something like:

if (($severity & error_reporting()) !== $severity)
{
   echo "Suppressing errors!";
   return;
} 

and you should be able to trap for surpassed errors, and debug from there.

Solution 22 - Php

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');

Solution 23 - Php

I was having same problem, i installed latest xamp version and found my site is not working, after research and wasting time i found that.

I need to turn on following tag in php.ini file short_open_tag=On

Make sure to restart apache after doing this.

Hope this helps, most of these problems are related to php.ini file or fresh installation if your site was already running as other people facing similar issue.

Solution 24 - Php

after installation of xamp/wamp you may notice few errors of similar nature. If your website was already running dont worry, it is a configuration related issue.

  1. check database connections in database.php file inside application folder
  2. check config.php file check url is correct or not?
  3. by default short tags are off in new installations then follow the procedure below

in php.ini file change "short_open_tag=Off" to "short_open_tag=On"

Make sure to restart apache after doing this.

hope this helps.

Solution 25 - Php

The error, In my case, was occurring because my Apache server was configured to run PHP as Fast CGI, I changed it to FPM and it worked.

Solution 26 - Php

Just for anyone who is still looking for answers:

$db['default']['dbdriver'] = 'mysqli'; (make sure you use mysqli, not mysql). (database.php)

Solution 27 - Php

If you get net::ERR_CONTENT_DECODING_FAILED in the console then you are using gzip in your .htaccess file but gzip encoding is Off.

Enable zlib.output_compression=On in php.ini and restart Apache

Solution 28 - Php

please check either error folder is in application folder of not in my case i replace error folder in application folder

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFlyingCatView Question on Stackoverflow
Solution 1 - PhpWesley MurchView Answer on Stackoverflow
Solution 2 - Phpalexanderlukanin13View Answer on Stackoverflow
Solution 3 - PhpMauricioRobayoView Answer on Stackoverflow
Solution 4 - PhpCode PrankView Answer on Stackoverflow
Solution 5 - PhpChristian GiupponiView Answer on Stackoverflow
Solution 6 - PhpRafael ParungaoView Answer on Stackoverflow
Solution 7 - PhpRookieDevView Answer on Stackoverflow
Solution 8 - PhpbrenjtView Answer on Stackoverflow
Solution 9 - PhpRafik BariView Answer on Stackoverflow
Solution 10 - PhpVytautas KrutulisView Answer on Stackoverflow
Solution 11 - PhpJunaidView Answer on Stackoverflow
Solution 12 - PhpAnand MishraView Answer on Stackoverflow
Solution 13 - PhpSavaş Dersim ÇelikView Answer on Stackoverflow
Solution 14 - PhpAndrew KosterView Answer on Stackoverflow
Solution 15 - PhpBK004View Answer on Stackoverflow
Solution 16 - PhpKeith RitterView Answer on Stackoverflow
Solution 17 - PhpAlexander MillarView Answer on Stackoverflow
Solution 18 - PhpevadeView Answer on Stackoverflow
Solution 19 - PhpSachinView Answer on Stackoverflow
Solution 20 - PhpCodeforView Answer on Stackoverflow
Solution 21 - PhpDave StricklerView Answer on Stackoverflow
Solution 22 - PhpOjchrisView Answer on Stackoverflow
Solution 23 - PhpUMAR-MOBITSOLUTIONSView Answer on Stackoverflow
Solution 24 - PhpUMAR-MOBITSOLUTIONSView Answer on Stackoverflow
Solution 25 - PhpJhonnyView Answer on Stackoverflow
Solution 26 - PhpRam GorreView Answer on Stackoverflow
Solution 27 - PhpAdrian P.View Answer on Stackoverflow
Solution 28 - PhpravikantView Answer on Stackoverflow