Mac OSX Terminal doesn't display PHP exceptions - php

Does anyone know what needs to be done for the terminal to display exceptions thrown by the PHP code? At the moment when I trigger for instance php index.php I don't get anything even though the code within the index.php file fires the exception.
I have all error logging set to true in my php.ini (running with Mamp).

You need to have these lines uncommented in your default php.ini:
error_reporting = E_ALL
display_errors = On

Related

Display PHP Errors in IIS

I am trying to get PHP errors to display on the screen using IIS vrs 8.5 and PHP vrs 5.2.17, but I continue to get the IIS 500 error http page, or a blank screen. I have already found numerous SO posts that have supposed fixes, but nothing on them has fixed my problem yet. Here is what I have tried.
Changed errorMode to Detailed. Still getting the 500 error page instead of the php error.
Removed all of the custom errors in the default IIS config file under the "httpErrors" block. Still getting the IIS custom 500 error page.
Added existingResponse="PassThrough" to my httpErrors block in the default IIS config. Doing this causes me to get a blank page instead of the php error, or the IIS 500 error.
I have verified that none of these settings are being overwritten in the site default system.config files.
Currently I am getting a blank page instead of the IIS 500 error on the screen. I have already verified that display_errors is on, and error_reporting is correct. I also know that the php page runs just fine. I am purposely causing this php error by removing a semi-colon on the page. So I already know everything is working fine. PHP Error logging is also working, but I want the errors to display on the page so I dont have to look at the error log every 5 minutes.
What else could be causing this?
IF you set custom error to Detailed in feature settings of error pages for website and server both
AND if in your php.ini file you set the display_errors = on & error_reporting = E_ALL
THEN there is only one possibility for getting [IIS default 500 error page] is that "Your PHP is not working coz of miss configuration."
The required configurations are:
After setting Handler Mappings to your php-cgi.exe file(which is in you php installation dir) as FastCGI, open the php.ini file and edit following lines OR add if not found in file. (if php.ini is not exists in you PHP installation dir then rename from existing php.ini-development OR php.ini-production)
1) extension_dir = "ext\"
;ext folder will be in PHP installation, if not create and don't forget ending \
2) log_errors = On
3) error_log = "C:\inetpub\temp\php-errors.log"
4) cgi.force_redirect = 0
; may be you need to add this line add it anywhere, for instance-before '; File Uploads ;'
5) cgi.fix_pathinfo = 1
6) fastcgi.impersonate = 1
7) fastcgi.logging = 0
Be careful and there should not `;` before any of these lines.
see documentation - installing/configuring PHP
Even after correct configurations PHP may not work because of system corruption. You can check by double click on php-cgi.exe and php-win.exe it should run without proper error (other then warnings OR ext/fileName... is missing messages - these are OK).
Note: after these many other setting are requires to run all things of php (ex. session), but by these SIMPLE PHP WILL WORK or PHP will properly show the error for what's wrong (NOT 500 page).
Make sure you are editing the right php.ini file. To check which file needs to be edited, go to IIS > Handler Mappings and look for PHP. Then check which directory they are located in.
In my case, I had two directories and was editing the wrong php.ini file, which was the reason why I was unable to get the errors to display.
I was having a similar issue getting a 500 error instead of a PHP error. I fixed the issue by going to PHP Manager within IIS
Under PHP Settings click configure error reporting. This will allow you to choose between Development and Production machine. If you choose Production you will get no detailed PHP errors in the browser, you will only get wrritten to a logfile. Development will allow for both errors to be displayed and written to a logfile.
I hope this helps.
If ou are Getting error 500 when active php to show errors, maybe you need to turn off the tracking error
Follow the step by step to fix.
If you don't have downnload the PHP Manager for IIS, you can find it in Web Platform Installer. Then open it.
After that click on manage all settings
Now Just turn off this setting
under server configuration feature view you see fast-cgi settings,
double click it. you see php-cgi.exe. double click it. set standart error mode to IgnoreAndReturn200.
regards
I was struggling with this issue - I have my PHP Handler Mapping set as follows, confirming I'm using PHP 5.3:
Therefore I then went to the corresponding location to find the correct file, here: C:\Program Files (x86)\PHP\v5.3 and edited php.ini
At first it looked like this:
; error_reporting
; Default Value: E_ALL & ~E_NOTICE
; Development Value: E_ALL | E_STRICT
; Production Value: E_ALL & ~E_DEPRECATED
I changed it to this:
error_reporting(E_ALL);
; Default Value: E_ALL & ~E_NOTICE
; Development Value: E_ALL | E_STRICT
; Production Value: E_ALL & ~E_DEPRECATED
I had to restart the Server in IIS to apply the change (choosing the Server from the list at the top on the left hand side, rather than selecting the Site on the left, lower down):
Now I see the error message - e.g.
Parse error: syntax error, unexpected '=' in C:\data\test.php on line 2
Instead of this type of generic error - e.g. on Chrome:

Why does $some_array['an-undefined-key'] throw an error on Mac but not Wamp?

For some reason my Mac is displaying the error message "Undefined index: an-undefined-key" whereas on Windows with WAMP it gracefully ignores the exception.
Example of usage:
if ($some_array['an-undefined-key']) {
// ...
}
Is there a PHP configuration which changes this behaviour?
I realise that I can do the following, but I would rather use the above technique if possible:
if (isset($some_array['an-undefined-key']) && $some_array['an-undefined-key']) {
// ...
}
Yes, you need to adjust the error_reporting and display_errors settings which sounds like they are different between your two different environments.
Here are links
error_reporting
PHP ini_set - look at first example for display_errors
The difference between the PHP on your Mac using the installed repo and your WAMP server is the php.ini, try editing your script and append the following lines to the top:
ini_set('display_errors', '1');
error_reporting(E_ALL);
This should be on your scripts. If this is not the problem, then please comment back and I will change accordingly.
You should not add unnecessary line to your script as you will have to change them when you go live.
Edit you php.ini ( using the wampmanager menus so you get the correct file )
left click wampmanager -> PHP -> php.ini
Look for these parameters and change to these values
error_reporting = E_ALL
This one makes error show on the web page
display_errors = On
error_log = "c:/wamp/logs/php_error.log"
this one will make the errors log into the file specified by error_log even if they dont show on the screen
log_errors = On
WAMP comes with XDEBUG configured so you should now see big orange errors in the web page
Check the bottom of the php.ini file for this line. Numbers for versions may differ on your system
; XDEBUG Extension
zend_extension = "c:/wamp/bin/php/php5.X.Y/zend_ext/php_xdebug-2.2.0-5.3-vc9.dll"

PHP errors make page inaccessible

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.

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

Parse errors are not displayed

I want PHP to display parse errors on screen. What I get instead is a blank page. Nothing gets written to server's error log file.
My setup: PHP5.2.9/IIS 6 (not Apache!).
My PHP.INI:
error_reporting=E_STRICT
display_errors = On
display_startup_errors = On
log_errors = On
error_log = "C:\Program Files\Zend\ZendServer\logs\php_error.log"
How do I get parse or fatal errors to be either logged or shown on screen?
Thanks,
Temuri
UPDATE: After playing with different switches it looks to be an IIS specific problem. ANY IDEAS FOLKS?
Setting error level in php file itself does not resolve the problem here because the file itself cannot be parsed !!
You need to change error_reporting line in your php.ini as follows:
error_reporting = E_ALL
BTW: There are some examples in php.ini file about what to do to display which type of error messages.
Good luck,
mcemoz
Apache doesn't always like to report parsing errors either. From the command line, run
php -l <file>
The -l switch tells PHP to check file syntax. See the man page.
E_STRICT is not included in E_ALL (until PHP 6). If you want to keep getting E_STRICT
In php.ini:
error_reporting = E_ALL | E_STRICT
At runtime:
error_reporting( E_ALL | E_STRICT );
You'll need to set the error reporting level (and display_errors) in php.ini to see syntax errors. If PHP encounters a syntax error, the runtime doesn't get executed, so setting at runtime won't work. (See the display_errors link.)
You can verify the script syntax with this command in terminal:
php -l path/to/file.php
Personally, I added this line to my ~/.bash_profile file so I can easily run php -l on all files in the current working directory:
phpl() { for i in *.php; do php -l $i; done }
If you're really hardcore, you can even run your app from the command line. You'll have a much better chance of seeing compile-time errors, and it's just kinda cool.
You can use the $argv variable to get the first argument, $argv[1], then use that as the request.
<?php
// show those errors!
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
// simulate a web server request
$request = '/' . isset($argv[1]) ? ltrim($argv[1], '/') : '/';
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'] = $request;
Then you can run your script via command line. This would be the equivalent of visiting:
your-webapp.com/request/uri/here
php /path/to/script.php request/uri/here
Here is a more comprehensive example for running CodeIgniter via command line. It should work for many other frameworks too: http://phpstarter.net/2008/12/run-codeigniter-from-the-command-line-ssh/
As Rasmus Lerdorf suggests, always use error_reporting(-1) on development server.
Re: Blank screen of php death death, I discovered that setting
php_value error_reporting "E_ALL" or
php_value error_reporting 8192
in .htaccess on my Windows 7, Wampserver w/ apache 2.2.4 and php 5.3.13 are sure ways to get the blank php error screen -- today, June 3, 2014. These htaccess lines DO set the desires value in phpinfo(), but the display of the errors happens only when the line is commented out (not used) in htaccess.
BUT... the next minute I discover that
php_value error_reporting 8191
DOES set the phpinfo() value AND also allows display of the error messages to the browser! D'oh! It must be an integer and also apparently a particular or valid integer, and not just a large enough integer!
If you're using Zend Framework (v1) and you're using the Autoloader, the following code will prevent parse errors from being displayed:
self::$Autoloader->suppressNotFoundWarnings(true);
See the following answer for more details:
Display php errors when using Zend framework
Try this.
error_reporting(E_ALL);
ini_set("display_errors", 1);

Categories