Solved

Error Log Not Being Written

Posted on 2004-04-13
7
246 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now