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
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).
My current php.ini reads:
error_log = error_log
And it is fine, it logs the errors of all scripts into separate files, depending on what folder they are in. So it gives a result like this:
public_html/error_log
public_html/folder1/error_log
public_html/folder2/error_log
But is it also possible to, in addition to this, make it log to one general error_log? Like below?
public_html/general_error_log_for_all_folders
public_html/error_log
public_html/folder1/error_log
public_html/folder2/error_log
error_log = /absolute/path/to/error_log
if you want to setup different error logs for some applications, use runtime config, .htaccess for example
php_value error_log = /absolute/path/to/public_html/certain/app/error_log
Though I have read lots of posts and pages concerning the issue (shown below), I guess I'm missing something here. The mais issue is: my PHP errors are not being logged to the file specified nor to the system event log.
My phpinfo() shows: Windows Server 2003, PHP 5.3.6, log_errors = On, error_log = C:\\errorphp.log
I have tried both error_log = C:\Inetpub\logs\php.log and error_log = syslog in php.ini to no effect (either one at a time).
I have:
restarted IIS after every php.ini change
granted the IUSR_XXXXX User Modify permissions on the folder AND the file
tried leaving the directory blank and letting PHP create the file
had a headache.
Any help is much appreciated.
references:
PHP Manual - PHP on IIS 6
Store PHP errors in a log file
IIS PHP doesn't log errors to log file
My php error log file is empty
Running a defect php file cause error 500
Logging PHP to Windows Event Log
In my case, setting
fastcgi.logging = 1
in php.ini solved the issue and I do have the log file working now (I left the file creation to php itself, my directory was blank)
I'd never guess that as the php.ini itself states (right above the stated config)
; Disable logging through FastCGI connection. PHP's default behavior is to enable this feature.
Go figure.
Have you
checked your error_reporting level
tried setting a log file inside the document root (incl. permission to write) to see if any restrictions apply?
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.
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.)