Solved

Error Log Not Being Written

Posted on 2004-04-13
7
248 Views
Last Modified: 2008-03-10
Hi all,

I'm trying to have PHP write all errors to a file (phperrors.log) but the file is not being written when an error occurs.  Maybe you can point out what I'm missing.

PHP.ini
----------------
error_reporting = E_ALL
display_errors = On   I'm leaving this on till I can get the file to write.
log_errors = On
log_errors_max_len = 0
error_log = ".:/Users/Me/Sites/phperrors.log"


Like I said, I'm visually seeing the errors but the log file isn't being written.

Thanks,
\m/
0
Comment
Question by:fatfe
  • 4
  • 2
7 Comments
 
LVL 14

Expert Comment

by:ThG
ID: 10818562
Why on earth are you using that syntax? can't you just use:
error_log = "/Users/Me/Sites/phperrors.log"

also make sure it is really writable by the web user, if you are unsure, try:
error_log = "/tmp/testing_errors.log"
0
 

Author Comment

by:fatfe
ID: 10819242
Thanks ThG,

I tried error_log = "/Users/Me/Sites/phperrors.log" and an error log was not created.
When I tried error_log = "/tmp/phperrors.log" the error log was written.  But what I want to get around is have to go to the command line to pull up the error log.  I would rather have it written to my user directory where I can easily pull it up in say TextEdit or some word processor.  I take it a change in permissions on that file would allow it be written to the location of my choosing?
0
 
LVL 14

Accepted Solution

by:
ThG earned 125 total points
ID: 10819259
yes but not only. You also need to make sure that ALL the upper directories have "access permission" (+x) for the web user, generally included in the "o" (others) permissions. so:
chmod +x /Users
chmod +x /Users/Me
chmod +x /Users/Me/Sites
touch /Users/Me/Sites/phperrors.log
chmod 666 /Users/Me/Sites/phperrors.log
666 means read-write permission for all.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:fatfe
ID: 10819317
My Unix background isn't that strong.  So my question is in changing the permissions on ALL the upper directories leading to this error log file what type of access will other users have, if any, to these changed directories?

Thanks for the quick response.
0
 
LVL 14

Expert Comment

by:ThG
ID: 10825958
+x means they will only be able to "cd" to your directory, but not list files (it could be insecure anyway, so you should store your error log somewhere else.
of course everyone will be able to write to your log file, given that they know the exact name.
0
 
LVL 9

Expert Comment

by:e-tsik
ID: 11443304
Hi :-)

I know it's a long time, but I found your question in Google, and ran into the same problem myself.

As a rule of thumb, PHP does log, if you allow the apache user to write the file in that folder. For example, if you'd write the log to /tmp (e.g. /tmp/php.err.log) you certainly would not have any permission problems.

PHP Would NOT log if:
1. It has no write permissions the log file.
2. error_reporting is disabled, even with the PHP function(!). If you have somehow disabled error reporting, then put back on!
3. If you've used error trapping (using set_error_handler() )- then PHP would not log - it would count on you to log instead using the error_log function:
 function MyErrorHandler ($errno, $errstr, $errfile, $errline)
        {
                error_log("error: Errno: $errno; ErrStr: \"$errstr\"; ErrFile: \"$errfile\"; ErrLine: $errline");
..
.
.

Things to do:
1. Change your filename to "/tmp.php.err.log". Restart httpd and try log for that file.
2. Do a search for "error_reporting" both in /etc/my.ini (the PHP config file) and in your PHP files. Make sure there's nothing that sets it to 0 or E_NONE.
3. Do a search for "set_error_handler"  in your PHP files. If you see one, look for that function is sets to and put
   error_log("error: Errno: $errno; ErrStr: \"$errstr\"; ErrFile: \"$errfile\"; ErrLine: $errline");
   in the first line of the function.

Enjoy!
0
 
LVL 14

Expert Comment

by:ThG
ID: 12406597
fatfe, thanks for grading this question. I hope you resolved your problem.

Regards
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question