Solved

Error Log Not Being Written

Posted on 2004-04-13
7
252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 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