LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   cgi log permissions (http://www.linuxquestions.org/questions/programming-9/cgi-log-permissions-824094/)

doru 08-04-2010 06:57 AM

cgi log permissions
 
I am writing a cgi (in fact, fast cgi) application under Ubuntu using Apache, and I want this application to log messages to a file.

The problem is that /var/log, and most files in it, has write permission for root only, while the process runs as www-data. How should I solve this problem? Should I write to a file in /usr/lib/cgi-bin/ owned by www-data? This would work safely with logrotate? I am lost at this, please give me any idea.

paulsm4 08-05-2010 12:54 AM

Hey - so not the problem :)!

From the fast_cgi documentation:
Quote:

http://www.fastcgi.com/mod_fastcgi/d...d_fastcgi.html

mod_fastcgi logs FastCGI application error (stderr) output to the server log associated with the request. Errors reported by the FastCGI process manager, fcgi-pm, are reported to the main server log (typically, logs/error_log). Data written to stdout or stderr before entering the FastCGI accept loop or via a mechanism that is not FastCGI protocol aware will also be directed to the main server log. If Apache's LogLevel is set to info additional informational messages are printed to the logs, these messages may be especially helpful while debugging a configuration.
So all you have to do is "printf()" or "fprintf (stderr)" - and voila! Your message automatically gets syslogged!

'Hope that helps .. PSM

doru 08-05-2010 03:34 AM

Quote:

Originally Posted by paulsm4 (Post 4056294)
Hey - so not the problem :)!

From the fast_cgi documentation:


So all you have to do is "printf()" or "fprintf (stderr)" - and voila! Your message automatically gets syslogged!

'Hope that helps .. PSM

Thank you, I did not expect to find a solution in fast cgi, because I expected a solution for all cgi programs.

I sort of prefer to log all activity of my fast cgi program in a separate file. I will put the log file in cgi-bin, I hope this will not be a security risk.


All times are GMT -5. The time now is 11:18 AM.