php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31419 error_log not able to be overridden...
Submitted: 2005-01-05 19:12 UTC Modified: 2008-08-09 16:48 UTC
Votes:12
Avg. Score:4.2 ± 0.7
Reproduced:10 of 10 (100.0%)
Same Version:3 (30.0%)
Same OS:3 (30.0%)
From: php at mfoxx dot myspamkiller dot com Assigned:
Status: Closed Package: PHP options/info functions
PHP Version: 5.2.0-8+etch10 OS: Debian 4.0
Private report: No CVE-ID: None
 [2005-01-05 19:12 UTC] php at mfoxx dot myspamkiller dot com
Description:
------------
FYI:  I am running a server where I built from source the apache and PHP binaries, so I am not susceptible to the problems other bugs reported where they might have used a pre-packaged binary with some other unexplained behavior.

If I set a value for error_log in my php.ini (to /home/php.errors, for instance), PHP correctly logs any errors encountered (in ANY of my <virtualhost> sites) there to that single file.

However, when I do in a script (because error_log is said in the manual to be modifiable as PHP_INI_ALL, which means i can change it anywhere):

ini_set("error_log","/path/to/some.log.file");

or when I do:

php_value error_log "/path/to/some.log.file"

in my httpd.conf inside a <virtualhost>, or my .htaccess file for a particular site, the VALUE is apparently "changed", but PHP doesn't seem to respect it, when coming across an error later in code.  Furthermore, PHP will not even write the errors to the original error_log value set before in the php.ini.  It will instead write them to apache's error log for that particular <virtualhost>.

As you can see in my "reproduce code" i change the error_log variable using ini_set(), then i do phpinfo(), and verify that it DOES IN FACT have the new changed value in its output, overriding the default that I set in my php.ini file.  And then I call a function which doesn't exist, which should force a PHP error.

The error does occur, and it DOES get logged, just not to the right file, it now gets logged to the APACHE error log file, not even the original php.ini error_log setting, which I find very strange.

Reproduce code:
---------------
<?php

ini_set("error_log","/path/to/php.err");

phpinfo();

echo nonexistent();

?>

Expected result:
----------------
I expected for the value of error_log to be changed, so that when I force a PHP error, calling a "nonexistent()" function, I should get the error logged into my php.err file as specified in ini.set.

Actual result:
--------------
the error (call to undefined function) DOES get logged, but to the wrong file... it gets logged to the Apache error file for that particular <virtualhost>.  It doesn't even get logged to the original php.ini file's setting for error_log.

But, as I stated before, if I just set the value in php.ini, and DON'T try to modify it in code (or httpd.conf), then the error gets logged to the location I specified in php.ini.

So, basically, when you try to modify the error_log setting at runtime, it irreversibly starts the PHP error logging to the Apache error log, no matter what you specify.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-28 23:24 UTC] mfoxx at hotmail dot com
I just installed the new CVS snapshot of this, and I am now seeing a different behavior, but still not the correct one.  Now, no matter whether I specify an error_log in php.ini or not, ALL php errors are going to the each  virtual-host specific apache error log.  I can't override it with a valid error_log setting in php.ini, nor can I override it in code, as my original bug report submitted that I had tried.
 [2005-07-18 18:46 UTC] mfoxx at hotmail dot com
I just upgraded to the latest Apache 2.0.54, and PHP 5.0.4, and again, I am still having the same problem.

I go into my php.ini file, and I comment out the setting for the php error_log.  I then create a script like this:

<?php

ini_set("error_log","/path/to/logs/php-err.txt");
phpinfo();
nonexistent();

?>

When I examine the output of phpinfo(), i see the value set in the ini_set() call.  

However, the error that occurs when I call the nonexistent() function does NOT get logged to that file (nor does the file even get created). It however does get logged to the virtual-host specific apache error log (error.log) that is set to be in the same directory.

I even tried creating an empty file (thinking maybe it was the creation of the file that wasn't working) in the logs directory, and then restarting apache.  Reran the script, and still, the error gets logged to the apache log for that virtual-host, not to the value set by ini_set().
 [2005-07-18 18:52 UTC] mfoxx at hotmail dot com
Also, here is the VirutalHost directive from httpd.conf:

<VirtualHost xxx.xxx.xxx.xxx>
        ServerAdmin xxx@xxx.com
        DocumentRoot /www/xxx
        ServerName www.xxx.com
        ErrorLog /www/logs/xxx_com-error.log
        CustomLog /www/logs/xxx_com-access.log common
</VirtualHost>

The apache error log I keep referring to, that is getting the PHP errors logged to it, is the one specified above at "ErrorLog", xxx_com-error.log.
 [2005-07-18 19:26 UTC] sniper@php.net
Using latest CVS snapshot (5.1-dev) this works just fine,
provided the path passed to error_log is such that the webserver can write into it. And I don't get any PHP errors in the apache logs either.

Check the permissions. And if that wasn't the cause, check what php.ini file is used (shown in phpinfo() output) and do a 'diff -u' between that and php.ini-dist from the latest CVS snapshot you're using.

 [2008-08-06 13:58 UTC] alexey dot portnov at gmail dot com
Description:
------------
FreeBSD 6.2-RELEASE
apache 2.2.9, php-5.2.6, (from ports)

php.ini config: /usr/local/etc/php.ini
error_log = /home/sites/php_logs/php_errors.log


PHP will not even write the errors to the original error_log value set
 in the php.ini.  It will instead write them to apache's error log
for that particular <virtualhost>.


The error does occur, and it DOES get logged, just not to the right
file, it now gets logged to the APACHE error log file, not even the
original php.ini error_log setting, which I find very strange.

Reproduce code:
---------------
<?php

phpinfo();

echo nonexistent();

?>

Expected result:
----------------
When I force a PHP error, calling a "nonexistent()" function, I should get the error logged into my /home/sites/php_logs/php_errors.log file as specified in /usr/local/etc/php.ini

Actual result:
--------------
the error (call to undefined function) DOES get logged, but to the wrong
file... it gets logged to the Apache error file for that particular
<virtualhost>.  It doesn't even get logged to the original php.ini
file's setting for error_log.

PHP writes errors in $error_log only when I run scripts from CLI:
php /path-to/script.php
 [2008-08-06 14:53 UTC] php at mfoxx dot myspamkiller dot com
I *still* have this same problem, 3+ years later, in that if I run PHP (now 5.2.0 on Debian Etch, originally v4.x and then 5.0.4 on Debian Woody) through Apache with VirtualHosts that set apache "ErrorLog" settings in the VirtualHost, then PHP will not log it's errors to a separate ini specified (either in php.ini or with ini_set()) php error file, but will instead put the errors in the apache error log.

This same problem has occured whether I use a custom build of PHP or whether I use the debian package builds (as I do now).
 [2008-08-07 19:54 UTC] kc6r5jsp74mzt03 at bodhi dot lawlita dot com
Hello,

same issue on Windows:

PHP Version 5.2.4 (ZendCore 2.5.0)
Apache 2.2.9

In httpd.conf I set the default ErrorLog value:
ErrorLog "D:/Logs/default_error.log"

I created a vhost with a customized ErrorLog value:
<VirtualHost *:80>
   ServerName   foobar
   ServerAdmin	null@devnull.invalid
   DocumentRoot	"D:/Webs/www1/htdocs"
	
   ErrorLog "D:/Logs/www1_error.log"
   CustomLog "D:/Logs/access_www1_%Y-%m-%d.log" common
</VirtualHost>
 [2008-08-09 16:48 UTC] jani@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC