Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - attempt to log using error_log() causes 500 error

I have an IIS server which is serving PHP via fastcgi. When the error log file is written to by a user other than one in IIS_IUSRS group (The group the IIS User is running under) the file becomes un-writable by IIS and the PHP calls to error_log() causes a 500 error. (At least that's my guess seeing as if I delete the log file, the error dissapears and the log file is re-created).

Is there anyway I can stop the 500 error from happening?

EDIT: To be clear I know I can stop this by stopping logging, logging to event log or different location etc, but that's not what I mean. I mean I just want to prevent the 500 error, I don't care enough that my system can't log that it should break the site when it tries to. That's exactly the worst behaviour it could have. I just want the 500 error to not happen and the site to continue working.

like image 918
Matt Fellows Avatar asked Jun 18 '26 13:06

Matt Fellows


2 Answers

Since your scheduled task is actually changing the permissions on the error log file, the only viable options I can see are:

1) Make the scheduled task not write to the error_log. Add the following to the top of the cron job:

error_reporting(E_NONE);

2) Make the scheduled task write to the system log (event viewer in windows) by issuing the following command at the start of your scheduled task (PHP file):

ini_set('error_log', 'syslog');

3) If all of the above do not suit you, you can try scheduling the task as the IIS User/Group. This would insure that the permissions are met and error 500 is no longer caused.

There is no magic fix to this, you can either change the scheduled task so it has the same UID/GID as the PHP process, or you can stop logging in the scheduled_task.

like image 151
Octav O Avatar answered Jun 21 '26 01:06

Octav O


Edit the php.ini, and find this line and edit:

error_log = /your/website/path/to/log

And sure to change the display_errors to off:

display_errors = off

Remember to put chmod 777 to the file :). If u wanna to see the file in the browser, can put something like this in the .htaccess file:

<Files /your/site/path/to/log/file.log>
    allow from 10.0.1.1/16
    deny from all
</Files>

PS: Sry, i dnt see the notation are a ISS server... hum, maybe can view more information about the error in the error_log of the ISS (i dont know where is)

like image 42
wiitohzjeh Avatar answered Jun 21 '26 03:06

wiitohzjeh