49

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.

Wesley Murch
  • 95,417
  • 36
  • 177
  • 220
FlyingCat
  • 13,288
  • 34
  • 109
  • 184

28 Answers28

109

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.');
    }
}
Wesley Murch
  • 95,417
  • 36
  • 177
  • 220
30

Make sure php5-mysql is installed.

alexanderlukanin13
  • 4,119
  • 21
  • 27
  • 5
    I encountered the same problem and after 20 minutes of debugging (using the tips presented in other answers) I found out that CodeIgniter serves blank page just because php5-mysql is missing. So I hope my answer will save someone's time. – alexanderlukanin13 Feb 17 '14 at 12:37
  • 2
    I've encountered this same problem a few times. Codeigniter really needs a patch for this behavior. In fact, I'm going to pull their repo and look into it myself. +1 to you sir. – Eric Uldall Feb 24 '14 at 18:45
  • While not EXACTLY my problem, it was very closely related. For windows users, make sure to include your php and php\ext folder in your PATH variable and then restart apache.... – dangel Jul 14 '14 at 03:36
  • +1 to alexander and thank you. Same problem here installing for LLMP (Lighttpd, Mariadb). You get distracted for a moment and you type "sudo apt-get install php5-cgi" and miss "php5-mysql". It's a pity there's nothing to tell you what just happened if you don't already have a basic non-codeigniter php5 database example to run already. – carveone Sep 06 '14 at 11:39
  • You saved my day ! Thanks a lot. – Vincent Decaux Nov 11 '14 at 08:52
  • +1 Had to dig out an old site I did in CI, I knew I hadn't set up.the DB, you just presume it will throw an error somewhere along the way if that's the issue. I was blaming nginx until I saw this, apt-get and voila the DB connection error I would have liked to have seen yesterday. – SwiftD Jul 27 '15 at 21:27
  • This was my problem as well. I would have been nice if some sort of "can't connect to database" or something had been displayed. Odd it wasn't, even with full logging enabled... – Marcello Romani Nov 08 '15 at 23:15
  • Spot on, you just saved my sanity! – zoider23 Oct 01 '19 at 14:36
11

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.

MauricioRobayo
  • 1,720
  • 17
  • 21
7

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.

Code Prank
  • 4,049
  • 5
  • 29
  • 45
  • I agree. I just need those base syntax error shown cauz I miss ; or ' a lot. +1 – FlyingCat Mar 06 '12 at 16:29
  • 2
    I have faced same situation too many times but did not find anything working. My suggestion is to use good IDE like dreamweaver CS5 which prompts you for syntax errors. – Code Prank Mar 06 '12 at 16:35
6

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.');
}
}
Christian Giupponi
  • 6,801
  • 8
  • 55
  • 99
5

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

Ulrich Schwarz
  • 7,355
  • 1
  • 30
  • 43
Rafael Parungao
  • 119
  • 2
  • 2
4

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.

Community
  • 1
  • 1
RookieDev
  • 41
  • 1
  • 4
3

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

Rafik Bari
  • 4,473
  • 17
  • 61
  • 121
  • Sjees, it does happen. In my case there was a default index.html on a clean installed lamp unit. Thanks for pointing me to the thing I obviously should have checked 8-D – Jos Faber Oct 09 '15 at 07:56
3

Try adding this to your index.php file

error_reporting(E_ALL);
brenjt
  • 15,133
  • 11
  • 74
  • 114
2

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.

Yu Hao
  • 111,229
  • 40
  • 211
  • 267
Anand Mishra
  • 374
  • 2
  • 12
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Andresch Serj Apr 23 '14 at 08:51
  • This is the exact issue i have faced, before i posted. In my case also there is no error message displayed, only blank page comes. I have given permission to CI folder in ubantu and restarted the apache server and it works. – Anand Mishra Apr 23 '14 at 09:35
2

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.

Christian Giupponi
  • 6,801
  • 8
  • 55
  • 99
  • Thanks Vyrautas, I tried your way and it gave me server error 500 now if I have errors. Still don't show the php error message. +1 though. – FlyingCat Mar 06 '12 at 16:27
2

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

Junaid
  • 1,996
  • 1
  • 19
  • 30
1

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.

Andrew Koster
  • 987
  • 1
  • 14
  • 23
1

In your index.php file add the line:

define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
Ralf
  • 13,322
  • 4
  • 31
  • 55
0

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.

kleopatra
  • 49,346
  • 26
  • 88
  • 189
BK004
  • 382
  • 2
  • 10
0

Are you using the @ symbol anywhere?

If you have something like:

@include('page_with_error.php');

You will get a blank page.

Keith Ritter
  • 321
  • 3
  • 3
0

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.

0

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.

evade
  • 139
  • 2
  • 13
0

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.

Sachin
  • 1,119
  • 12
  • 17
0

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);
Codefor
  • 1,212
  • 2
  • 11
  • 20
0

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.

Dave Strickler
  • 131
  • 1
  • 5
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');
Ojchris
  • 119
  • 1
  • 3
  • 10
0

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.

UMAR-MOBITSOLUTIONS
  • 73,009
  • 94
  • 197
  • 273
0

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.

UMAR-MOBITSOLUTIONS
  • 73,009
  • 94
  • 197
  • 273
0

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.

Ahtisham
  • 5,216
  • 3
  • 29
  • 42
Jhonny
  • 1
  • 1
  • 2
0

Just for anyone who is still looking for answers:

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

0

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

Adrian P.
  • 4,484
  • 1
  • 40
  • 43
-1

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