I am running a php app on microsoft IIS . I am debugging a problem and wants to use the php.ini directive display_errors = stderr . I want to see the errors messages in a file .
Is it possible in php.ini to redirect the stderr (or stdout) to a file ?
That's what error_log is for.
You can get the errors logged into the file of your choice by appropriately setting the value of error_log.
Related
i have a developement dir on my server but i dont have root access so i cant change which php ini file loads. I ask my host if they would set things up so that i could have a custom php ini file but they dont allow that.
I am always having to go all the way back to the public dir to check the error log file during development. I would like to force the dev folder to create its own error log file. Is there a way to do this without root access. I just want to be able to check errors in the dev dir because its faster to check them.
I have already added a php.ini file to my dev dir. And inside that php ini file i have the error log location code
;just for testing
error_reporting = E_ALL
error_log = '/home/xxxxxxxx/public_html/xxxxxxxxx/xxxxxxx_dev/error_log'
but its probably not doing anything as they dont allow those. Can i do this with htaccess? or is there another way to do this for a local error log?
I am on a linux apache machine.
You can use set_error_handler() to change system default behavior.
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
// do something
}
set_error_handler('myErrorHandler');
This worked in the .htaccess file...
enable PHP error logging
php_flag log_errors on
php_value error_log /home/xxxxxxxxx/xxxxxxx/xxxxxxxxx/xx_dev/error_log
You can set error_log file in .htaccess, for example
# enable PHP error logging
php_flag log_errors on
php_value error_log /home/path/public_html/domain/PHP_errors.log
This file should be writable for apache process user (www-data, apache - see apache config).
I have in a php.ini in public_html that has
display_errors = on
error_reporting = E_ALL | E_STRICT
log_errors on
error_log /home/account/public_html/error.log
phpinfo shows that the php.ini file in public_html is being loaded. The error_log file has 755 permissions and belongs to the same group:owner as all other files in public_html.
But, when I force php errors, no errors are displayed or logged. Errors are logged in /usr/local/apache/logs/error_log. And I've restarted apache.
Any ideas?
Try changing:
log_errors on
error_log /home/account/public_html/error.log
To
log_errors = on
error_log = /home/account/public_html/error.log
Next, near the top of your script, do:
echo php_ini_loaded_file(); // to make sure that you're editing the right php.ini
echo ini_get('log_errors'); // should be '1'
echo ini_get('error_log'); // should be path from php.ini
If the settings don't match what you set (I assumed you restarted Apache), check the rest of the php.ini as well as Apache VirtualHost configuration for another setting that may be overriding yours.
When you runphpInfo(), it will sometimes show a list of ini files that get loaded (not just your basic php.ini. One of them could also contain an override.
Finally if none of that works, you could set error-logging in-script with ini_set(). Just be aware that if that script itself has an error, this setting may not have the chance to take effect so it's best to do it in a script separate from your main, and require it
main.php
require_once('./init.php);
// ... your regular script
init.php
ini_set('log_errors', '1');
ini_set('error_log', '/path/to/errors.log');
I'm taking a php course. I made a php.ini file to show errors.
I have the code below on my php.index file. But instead of the error being displayed just nothing shows up. What am I doing wrong?
index.php code:
<?php
$test="I"m a variable!";
echo $test;
?>
This my php.ini code:
display_errors = on
display_startup_errors = on
You should check your error reporting directives
error_reporting = E_ALL
display_errors = ON
But please note that PARSER errors are not being show in display errors, but in error_log.
What is 'php.index'?
Normally the index page is index.php
Where is your php.ini file located? Where is it supposed to be located?
Do you have access to php interpider (command line)?
phpinfo() can help you location the php.ini file(s)
Your file name should be index.php so your server can recognize it as a PHP file.
Make sure you are loading the php.ini file that you've created.
call phpinfo() and check the route of the php.ini to see if you are loading yours.
In asp I can access the log file in \Inetpub\logs\LogFiles\W3SVC1
there something similar on php language?
You have to go in you php.ini file.
Activate the log with this:
display_errors = On
Also, you may want to check where the log is written:
error_log = /var/log/YourFileWithLog.log
You can set a log file in the php.ini
I've narrowed my problem down somewhat.
When I run "error_log('hey');" from the command line it dumps to STDOUT. But if I run the same code from my web interface (Apache) it puts the error in the error log.
I've checked both ini files, the one Apache is using, and the one in /private/etc (I'm on a Mac running MAMP). Both error_log variables point to the exact same place.
And when I run
echo ini_get('error_log');
The value is the same on the command line as it is in the browser.
What ini setting is misconfigured here? This is quite annoying, as more than just error logging is broken. It's affecting my include paths as well :/
What are you trying to accomplish? Within apache, stderr goes into the error_log... the error_log() function documentation states that by default it logs to the server's error log. If you want to log to a different destination, use the message_type and destination parameters.
You probably need to edit the following config file:
/Applications/MAMP/conf/php5/php.ini
MAMP uses it's own Apache server, which by default runs on port 8080. You probably want to turn off the Apache server in the System Preferences -> Sharing.
Also, try running a PHP file containing:
<?php phpinfo(); ?>
This will tell you which php.ini is actually being read by Apache.
Will
A reason for error_log displaying in the console, and not in the log file might be because of a problem with permissions -- I don't really know MacOS, but as it's UNIX-based, I'm guessing that :
The log file used by Apache belongs to a specific user
When running the script from the console, you are not that user, and you don't have write-access to the log file
If it can't log to the log file, I suppose that error_log is writting to the standard output for error (stderr), which is generally the console.
This comment on the manual's page seems to indicate this might be the cause of your problems (quoting) :
it seems that PHP logs to stderr if it
can't write to the log file. Command
line PHP falls back to stderr because
the log file is (usually) only
writable by the webserver.
Also, make sure the log_errors and display_errors are properly configured in the php.ini file used in CLI :
log_errors boolean
Tells whether script error messages
should be logged to the server's error
log or error_log. This option is thus
server-specific.
And :
display_errors string
This determines whether errors should
be printed to the screen as part of
the output or if they should be hidden
from the user.
Value "stderr" sends the errors to
stderr instead of stdout.
The relevant ini setting here is display_errors.
From the command line a value of On will dump the errors to STDOUT; stderr will divert them to STDERR and Off will suppress them. For Apache only On and Off make any sense.
The odds are that the ini file for Apache has display_errors = Off whilst the one in /private/etc has display_errors = On.
The error_log directive tells PHP where to log errors to, but it also requires log_errors to be set to On, otherwise it has no effect. (Again, chances are the ini file in /private/etc has log_errors = Off.)