I happens all the time, and it freaks the heck out of every new/first time coder. You get to work on some code that, let’s face it, you know is totally over your head. You probably copied it from another blog, maybe even this one, and pasted it where you think it best fits, save, and ….. OH NO OMG WTF EHRMERGERD WHAT DO I DOOOOO???!! HALP!
You get the blank screen of death. You quickly start googling, posting on support boards, and jumping in to IRC chat rooms to find an answer. Running through your mind is all of those hours of work you just lost. Everything is wiped out… but how can that be?
It’s not. Chill out. A blank screen is not a death sentence, and you didn’t lose any work, you just borked it is all.
Causes for a blank screen
There’s a bunch of reasons to wind up with a blank screen, but chances are if you are in a situation close to the one described above, it’s because of a code error.
1.) Coding / Syntax Errors: A screen will display blank because, by default, it’s relatively unsafe to have a bunch of errors visible for all the world to see when your website is out there in the wild wild west, so typically “error reporting/display” is turned off. If you’re developing / debugging you are going to have to know what those errors are, so you have two options: Check your error logs or turn error reporting on.
**IF YOU ARE USING WORDPRESS:
WordPress has a nifty little setting called WP_DEBUG. This setting resides in your wp-config.php file which is in the root folder of your WordPress install. If you do not have a line in that folder that says ‘WP_DEBUG’ simply add it to the file. WP_DEBUG should be set to ‘true’ to see your errors output on the screen while in development mode. The line of code should look like this: define( 'WP_DEBUG', true );
Remember to always turn debugging tools off when going live!
Checking your error logs:
Log in to your cpanel account and find the little icon that says “error logs”. Click it. View errors. Fix errors.
Turn error reporting on:
- Look for a file called php.ini in your public_html folder (or website root)
- If the file exists, open it to edit it. If it does not exist, create one
- Add the below code to your php.ini file OR alter existing code to match it.
123# Displaying PHP errorserror_reporting = E_ALLdisplay_errors = On
This should show you the errors that were previously causing your blank screen. This could open a whole other can of worms for you but at least now you have a starting point to debug. If this does not work, it could be that you have some local code that is overriding it or something other than error reporting is causing your screen to go blank. Keep reading if that is the case.
If you are using WordPress then you also want to turn WP_DEBUG from ‘false’ to ‘true’. Prepare to be alarmed though, you might see a LOT more errors than you bargained for. Many plugins use old code that throws errors when debug is set to true but still allows for the code to function.
2) PHP Memory Limits could be met and therefore all things stop. A memory limit is basically put on PHP in order to stop certain scripts from eating up all of the server memory. The default is 128M but you can change this if you think you need to. I would highly recommend trying to find the memory leak if you can, but upping it isn’t a terrible thing. To change the limit you open (or create if it doesn’t exist) your php.ini file and add or edit the below code:
3) Other various things. Hah. So I know that sounds ridiculously vague and doesn’t help you at all, but there are a number of script specific things that can cause a page to go blank. I will give you a “for instance”.
I was working on a WordPress site that I knew for a fact had the WordPress debugging set to ‘true’ and my php.ini was set to display all errors. No matter what I did, a page I was working on would literally just display white! It made no sense at all. I later found out that it was an issue relating to how my permalinks were set (which is really an .htaccess configuration issue) and instead of getting my expected error or 404 screen, I got nothing!
Hopefully this will help you out and give you some solace it not only knowing that all is not lost, but you aren’t the only one to have experienced this exact same issue.
If you found another cause for a blank screen that could fit in the “Other” category, let me know in the comments!
*** Don’t forget to turn your error reporting off and your debug to false once you go live! ***