PHP errors make page inaccessible - php

Every time I have an error within my code and try to run it, the page becomes inaccessible. This is clearly very frustrating as it's hard debugging code with no feedback.
Relevant information from cPanel:
Apache version 2.2.22
PHP version 5.3.14
MySQL version 5.1.68-cll
Architecture x86_64
Operating system linux
If more information is required then please ask, I'm sorry I cannot provide any more information but frankly I am stumped.
Thanks.

Enable error reporting to see what error PHP had, if it had one.

There are several places you can look, firstly try checking your Apache error log. In many cases this is located in /var/log/apache2/error.log . Another way to debug a page like this is to enable error logging.
The simplest way of doing this being adding these lines to your php file:
ini_set('display_errors',1);
error_reporting(E_ALL);
In addition to this, you can also clean up the errors formatting by adding:
ini_set('html_errors', 'On');
In addition to this method of enabling error reporting, you may also enable them from you configuration file by adding the following line:
error_reporting = E_ALL

You need to update your php.ini to display errors. There are a couple settings.
Search your php.ini for display_errors and error_reporting. The file is usually commented very well on the options for error reporting, but error_reporting = E_ALL is a typical setting. Sometimes people want to suppress notices and set error_reporting to E_ALL & ~E_NOTICE.
display_errors = On is the config to print the errors to the screen.
After changing your php.ini, Apache usually needs to be restarted. I'm not sure how much control you have over your server, so if you can't restart Apache but you have a php.ini available, your host probably has it configured so you don't need to restart.

Related

I can't disable PHP errors

So what's going on is I tried
ini_set('display_errors', 'Off');
error_reporting(0);
Right below <?php, but this didn't seem to stop displaying them. So I went to the php.ini and went to display_errors and saw that it was set to Off. But it still showed.
So I went and did phpinfo() and display_errors along with display_startup_errors are both off. Also html_errors is off. I'm not sure if this will help, but it says error_reporting is set to -10241. Any ideas?
Do not change the value of error reporting to solve the issue. If display_errors is off, errors are not display independently of the error_reporting setting. This way you will not display errors but you can still log them.
The following should work:
ini_set('display_errors', 'Off');
If it doesn't work it could be that your server configuration does not allow you to change settings from PHP scripts. ini_set() returns FALSE on failure. So first of all you should check what value that call is returning. Make sure that ini_set is not listed among disabled PHP functions (disable_functions in php.ini).
If you are asking yourself why errors are still being displayed even if in php.ini the display_errors is Off, you can check the actual value of display_errors during the script execution:
ini_get('display_errors')
Pemember that PHP settings could be changed also in Apache host configuration and in .htaccess files. So check if you have an htacces that enables display_errors. Something like this:
php_flag display_errors on
Try to use:
ini_set('display_errors', 0);
ini_set('display_errors', false);
You don't describe what the errors are, so it's possible that your web server (Apache, nginx, etc) are what's throwing the error and not PHP.
If it is PHP, ensure that you're editing the correct php.ini as identified in your phpinfo.php. Remember that if you edit the php.ini, you will need to restart your PHP process (for example, on some *nix systems: service php-fpm restart. Your exact command may vary.)
If it's off in your php.ini, my guess is that it's being overridden somewhere else -- either later in the script ('grep "ini_set" /path/to/project/*.php' will find it). Also, the PHP Manual states that if the script has fatal errors, it doesn't apply if there are fatal errors:
Although display_errors may be set at runtime (with ini_set()), it
won't have any effect if the script has fatal errors. This is because
the desired runtime action does not get executed.

Display Errors only when I specify error_reporting Level

I've re-configured my Apache and now I want it to run in a better way.
To be more precise, I want to configure php.ini in such a manner that errors will only be displayed when I specify error_reporting so by default they wouldn't be displayed. This is because I'm developing a platform and I want to see errors as I go, then stop them for showing without having to go through the php.ini hassle.
I tried display_errors = Off but that wouldn't display errors even after I specify error_reporting level.
Ideas ?
First of all you should learn more about how you have to configurate your php.ini and know which command do what.
If you deactivate to display the errors there will be no errors displayed even if you set an error level.
But here is your answere: php.net
<?php
if (!ini_get('display_errors')) {
ini_set('display_errors', '1');
}
?>
with ini_set() during the execution of the script your options take action, after execution it is back to default.

PHP on OpenShift: How to enable errors and warnings?

I have moved my app to OpenShift and now, for convenience of getting it actually work, I'd like to enable in-page errors and warnings. Currently, I see a blank page.
How can I enable errors?
In PHP, it's in php.ini
error_reporting = E_ALL
display_errors = 1
On the IRC channel #openshift, I was told that this is not currently not configurable
(05:06:58 PM) pmorie: ozizka-ntb: it looks like it's provided by the cart - i don't believe you can substitute your own
and I need to use both
error_reporting(E_ALL);
ini_set('display_errors', 1);
You might want to set APPLICATION_ENV to development.
$ rhc env set APPLICATION_ENV=development
According to https://developers.openshift.com/en/php-getting-started.html,
In development mode, your application will:
Show more detailed errors in browser
Display startup errors
Enable the Xdebug PECL extension
Enable APC stat check
Ignore your composer.lock file (if applicable)
If you can't access php.ini then write this on top of your php page:
<?php
error_reporting(22527);
?>
This displays all errors and warnings in the page.

Error logging with WAMP server in PHP

I have a WAMP 2.2 server running on a Windows 7 box and cannot get PHP error logging working at all.
The file is always blank even after I explicitly trigger USER_ERROR errors, or cause normal ERROR errors.
I'm including the error relevant sections of the php.ini file - hopefully you can find something:
error_reporting = E_ALL
error_log = "c:/wamp32/logs/php_error.log" ;(UNCOMMENTED BY ME)
log_errors = On
display_errors = On
The line ; log_errors is just a comment for the following block, for the purpose of showing you what the settings are in dev vs production. You uncommented four lines which aren't meant to control anything, and I'm surprised your Apache service doesn't have problems starting up because of it.
What you need to do is look for the line:
log_errors = Off
And change the value to On
That said, once you restart the Apache service, the settings should take effect. However, I was unable to get WampServer to properly log php errors despite these settings. Apache will not start up when I specify the error_log parameter.
For me it turned out to be a permissions error. I ended up giving EVERYONE full control of the error log file and it seemed to fix my issue. Best of luck.
Did you try adding these lines to your php file?
ini_set("display_errors", "1");
ini_set("log_errors", "1");
ini_set("error_log", "/wamp64/logs/php_error.log");

php project deployment problem

i have done onw project in php. It works on my windows pc. I use xampp on my windows machine.But when i devlopy same on my linux machine it shows me some blank pages.
Some pages are completely blank.some are half blank.
whats the problem?
Those blank pages could be because there is an error that is not displayed -- will be hard to guess what, though, so here are a couple of pointers :
Did you check if there is anything useful in your Apache's log files (something like /var/log/apache/error.log, or close to that, generally).
You can also enable display_errors and/or configure error_reporting, to get more informations -- or have them displayed on screen, which might be a bit easier, as long as you are developping and your application is not deployed to the production server.
This can be done in the php.ini file, if you can modify it, with something like this :
error_reporting = E_ALL | E_STRICT
display_errors = On
html_errors = On
Or it can also be done directly in your code, at the beginning of it, with something like this :
error_reporting(E_ALL);
ini_set('display_errors', 'On');
To enable error_reporting for all kinf of errors, and display those errors.
You might also want to install Xdebug on your development box, to get nice stacktraces when an error / exception occurs -- just don't install it on a production server !
Of course, on your production machine, you probably don't want to display errors ; so that will have to be configured depending on your environment ;-)

Categories