Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't open writable file in append mode

Status
Not open for further replies.

frieze

Programmer
Apr 17, 2006
6
US
This is a problem from a cgi script but I can't see how it can be an apache/cgi problem. I have a cgi script that tries to open a file int eh cgi-bin folder for writing. the -W and -w tests show that the script can write to the file. However when I try to open the file using open(THEFILE ">>/var/ I get a failure with permission denied in the $! variable. It have tried every possible permissions setting on the file itself and the folder it lives in. Is there some situation wehre the -w and -W tests fail to work?
 
Try this.. You can also try adding file.txt to the apache group as well.

Code:
open (FILE '/var/[URL unfurl="true"]www/cgi-bin/file.txt')[/URL] or die $!;

 
yeah, I tried changing both the group and owner to apache. no change. the fact that the script can read from the file and the fact that the -w test indicates that the file can be written is what is so confusing to me. when I do the open (FILE '/var/ the file opens successfully. It's only when I do the open(FILE '>>/var/ that it fails. The -w test means that it should open successfully. I am totally stumped.
 
I've tweaked the permissions on that directory a lot. at this point they are all open: the ls -l reads drwxrwxrwx as does that of the file.
 
and at this point I can't write to any files from cgi. Maybe I should move this over to a different forum.
 
As long as perl -c script isn't showing errors and nothing odd is showing up in the error_log, then it may be a virtual host config problem. Are you running cgi's under suexec? And are the user/group set correctly for the virtual host settings in httpd.conf? S'bout all I can think of at the moment to check.
 
I'm not running it chroot'ed or anything like that. Perl is not throwing any errors because I'm checking on the open to see if it succeeds before writing to the file. I'm thinking that there is some httpd issue preventing it from writing to the file system. I'll hunt down a forum for that maybe.
 
Yeah, it's possible that the filesystem is full.

Code:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `df`;
 
nah, some other weird apache thing is happening I think. It turns out I am able to write to /tmp. Web stuff isn't really my thing so I was hoping to fix this without delving into apache configuration, but that seems to be the source of the problem.
 
Hmm, /tmp frequently is setup on its own partition. Hitting a quota limit on the web directory's partition?
 
Be sure that the user under which apache runs owns the file and he has permision to write on this file.
Also the whole directory tree from the root to that file has rwx for this user.
In httpd.conf you will find under which user and which group apache runs. You will see two lines looking like
Code:
User nobody
Group nobody
Be sure that you checking the right httpd.conf and also that the file is not in the cgi directory cause apache does NOT like writing in that directory.
It comes preconfigured like this
Code:
<Directory "/whatever/the/path/to/cgi-bin">
	Options None
	AllowOverride None     #this means no writing, [red]And believe me you don't want to change this[/red]
	Order allow,deny
	Allow from all
</Directory>
So move the txt somewhere else.
There is [red]No reason[/red] why you wouldn't be able to write to a file under a web server if the user that runs the web server owns the files has write permissions and also 777 on the directory tree(and this is not a directory that apache is configured not to write in).


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top