After debugging a CodeIgniter application that were installed into a new development environment, I have started to freak out when seeing white screens with nothing more available. I have been able to solve each and every one of the errors that have caused this, but it has taken seriously way too long time.
PHP error_reporting(E_ALL) & display_errors", 1 is set as well. I even installed Xdebug in hope of getting more output, but no. My logging settings are also working, but nothing is written to the log.
Is there a way to get something informative printed out instead of a complete white screen? It would certainly shorten my time spent on solving the eventual errors that cause this.
Reference:
Why does Code Igniter give me a white page?
If there's a fatal compilation error, then you may well get a blank page.
Try doing a
php -l <filename.php>
against your script
Look near the top of /index.php for a call to error_reporting() - and make sure it's not changing your php.ini configuration to something else (besides E_ALL).
And since you didn't mention your php.ini configuration, check to ensure you have error_reporting = E_ALL there as well.
I've found out, since the time of my question, that nothing seems to ensure that errors are always outputted with PHP, which seems to throw white screens here and there. Regardless of PHP's ini-settings.
I've found out that the best workaround however is to use the following line to ensure that error logging is put into a file easily is accessed and monitored by the application:
ini_set('error_log', MYPATH .'logs/errorlog.log');
As far as I've tested it, when white screens appear - it also gets logged into this errorlog. It seems to be the easiest way to know what happens when things go wrong.
Grep the files for 'error_reporting', and 'display_errors'. The application might turn it off somewhere.
Also, to be able to see parse errors, you need to set error_reporting/display_errors in the php.ini file, or a .htaccess file. Setting it in the script files will not do and will lead to the white page you describe if there are parsing errors.
Aside from everything else posted, also make sure that something masked with the # (error suppression operator) isn't throwing a fatal error.
The best thing is to have a checklist of the common problems that could cause this since CodeIgniter's default is already
error_reporting(E_ALL);
Same name controllers and models
using reserved words as methods
The list goes on...
Consider setting PHP's error_log configuration variable -- it can be helpful when you have code setting error_reporting() without your knowledge. Then you can check the error log and see what errors, if any, occurred.
I had this problem on my freshly installed server. Debian 7.
I enabled logging, error reporting, disabled gzip and so on.
However, my PHP-installation did not have MySQL enabled. Enabling MySQL did the trick for me.
Make sure your logs and cache folder inside /system are chmod'ed to 777.
Ensure that there isn't any whitespace in your files output outside of the CodeIgniter buffer, especially if compression is turned on. You can test this by turning off compression in your CodeIgniter configuration file.
See step two at: http://codeigniter.com/user_guide/installation/upgrade_141.html (Note that while this is for the upgrade, it contains a snippet of the configuration file which explains the problem.)
If you by chance have happened to create a cached output for that particular method inside your controller, then it may create a cached version of the page and practically that page is not even running.
The cached error output page is showing up. Please check your cache folder inside the application. It should only contain the index.html file.
Related
i am having weird situation last week i open my site and then i open my wp-admin page it should work like my front but i am having 500 error.
i tried almost every thing on google to find this situation but nothing helped me.
as i remember last time i work in theme function file and WordPress config file i checked .htaccess file eveything is fine.
also i did replace content with old content and create new file for config but nothing works. i disabled all plugins enabled debug mode but nothing helped me
what should i do ? i dont want to lose anything
Glad you sorted your error with incompatible PHP versions.
In order to properly debug an HTTP 500 error, you should do the following.
In your php.ini, set error_reporting to -1
Turn display_errors off
Set a custom error_log path.
Then in your terminal, type tail -f /path/to/error_log.
Now as you work on your project, you can go into your terminal and you will see all notices, warnings, deprecation messages, and fatal error messages, scrolling past in real time.
Then you can tighten the screws. An empty log means well written code!
I have a WooCommerce website that has been created by other party. When I was editing a template file and checking a minor change, a PHP error appeared on top of the page (literally the first line in the document, above )
[12-Jun-2017 19:08:58 UTC] PHP Fatal error: Call to undefined function add_action() in /home/SITENAME/public_html/wp-content/themes/booklovers/widgets/top10.php on line 8
I do know what it means, but it appears that the error itself is not the issue. The time does not change, it constantly displays 19:08:58. I've also tried renaming/moving the file to see what happens - and nothing happens at all. It is being executed, because the page results with a white screen when I put exit; in it. Renaming made no difference. Checking this path by file_exists() called in index results with false. In my opinion it has something to do with Wordpress, because if I put exit; on top of the index.php the page is totally blank, without error, so it is not being merged with the response by Apache or something. Also setting the error reporting in index/config has no effect (I realize that this is generally a bad idea, and would not leave production with a workaround like this).
My guess is that the error might be some kind of a cached artifact. But this WooCommerce has no cache plugins installed so far... I have only a minor experience with Wordpress, I do know the basics, but debugging this type of issues is a terrible pain. I would appreciate any tips suggesting where should I look.
Additional information worth mentioning: shared hosting on GoDaddy (not my choice...), php 5.6.
Resolved. A theme's error_log file was being prepended to the response.
This is something that has been bothering me for a while now and I'm sure there's a simple solution.
So my basic page structure starts like this with the every page file first and the header second.
require_once '../private/core/ep.php';
include template('header');
the ep file contains autoincludes for classes and functions, so everything inside of there occurs above the header. Whenever errors occur internally I often have to inspect the elements in my browser and navigate through the HTML to find what the error is which is really time consuming. Is there anyway around this?
There are a few things you can do to keep your errors from showing up in your header. If you have access to make changes to your php.ini you can configure your error log so that all of your php errors can be logged there and set display errors to false. These can also be set in your ep.php file at the very top using the ini_set function.
Another solution is to configure your own error handler using http://www.php.net/manual/en/function.set-error-handler.php
You can then open a terminal and use "tail -f /my/log/file/location" to actively monitor your errors.
You could write a LOG function to a file or better to a database.
You will see exactly where your code broke.
Another thing you can try in enable error reporting on your server (php.ini)
I don't think there is any other way.
Ovidiu
Whenever I have an error in my php code, MAMP just returns a 500 error. Is there anyway I can get MAMP to tell me what went wrong like parsing errors and stuff?
Just as you reported, you must have display_errors set to on. This can be done either by changing the conf file or by using .htaccess like so:
<IfModule mod_php5.c>
php_flag display_errors on
</IfModule>
Additionally, you can do this with ini_set() like so:
ini_set('display_errors', 1);
One last thing, you can also check /Applications/MAMP/logs which has three different error log files.
Try opening terminal and run this command:
tail -f /Applications/MAMP/logs/php_error.log
When you want to stop "following" (the -f switch) the log file, just type control+C.
You can also access MAMP errors using the Mac "Console" app to read the php_error.log file.
I find this easiest to access by using spotlight and typing in "error.log".
( it won't find it if you type "php_error.log", you must type "error.log" )
It looks like this :
2022 update:
If we talk about usual MAMP (not PRO version), my research showed that there's no way to enable displaying of PHP errors using GUI. However, all the old approaches with configuration files mentioned in answers to this question and several others still work. But be careful with config names since they have been changing over some versions.
For MAMP PRO users: You can easily enable outputting of PHP errors using GUI:
Switch to Expert view at the top left corner: screenshot
Click on the PHP language: screenshot
And then check the option to screen of the Log errors property: screenshot
Hit Save and restart the servers when MAMP asks you to restart or not.
You're done. PHP now should output error message in the place where error occured.
Also, if you prefer configuring everything by hand, the option with configuration files works here as well.
At the time of writing this answer, the actual version of MAMP (and PRO) was 6.6.2.
My apache error log is located at /var/log/apache2/error.log. I've been using it to debug a simple PHP script I'm writing.
Now, suddenly it isn't catching anything. I've tried putting in known errors like calling functions that don't exist and nothing shows up.
Maybe check that Apache still has access to this folder and this file.
Solved by restarting Apache. It turns out that I "broke" it myself by editing the log file.
Note to self: Do not do that.