CGI生成日志文件出现权限问题

CGI生成日志文件出现权限问题

我照书上写的一个CGI,可不能正确的运行起来,查看HTTP的日志文件,提示:
could not open log.txt: Permission denied at /var/www/cgi-bin/fig10_11.pl line 14.
Premature end of script headers: fig10_11.pl

我赋予了/cgi-bin目录的权限为777,日志照样是这两条.
CGI程序如下:
use strict;
use warnings;
use CGI qw(:standard);
use Fcntl qw(:flock);

my @vars = qw(REMOTE_ADDR REMOTE_PORT REQUEST_URI QUERY_STRING);
my @stuff = @ENV{@vars};
my $info = join(" |",@stuff);

open(FILE,"+>>log.txt") or die "could not open log.txt: $!";
flock(FILE,LOCK_EX) or die("could not get exclusive lock: $!");
print(FILE "$info\n\n");
flock(FILE,LOCK_UN) or die("could not unlock file: $!");


close(FILE);

if($stuff[3] ne "")
{
        print (header( -Refresh => '5;URL=http://202.204.118.146/macis/'));
        print (start_html("log.txt"));
        print (h1("welcome to macis, $stuff[3]!\n"));
        print (p(i("you will now be redirected to our home page.")));
}
else
{
        print (header());
        print (start_html("log.txt"));
        print (h1("please add a \"?\" and your name to the URL.\n"));
}

print (end_html());
请问这是什么原因?如何解决?谢谢!!!
open(FILE,"+>>log.txt") or die "could not open log.txt: $!";
改用絕對路徑....
还是不行啊.
但我用perl fig10_11.pl运行就可以创建log.txt文件.


QUOTE:
原帖由 chinaseen 于 2006-3-15 18:06 发表
还是不行啊.
但我用perl fig10_11.pl运行就可以创建log.txt文件.

把写log.txt文件的目录的属主改成apache运行的用户如nobody。


QUOTE:
原帖由 chinaseen 于 2006-3-15 11:15 发表
我照书上写的一个CGI,可不能正确的运行起来,查看HTTP的日志文件,提示:
could not open log.txt: Permission denied at /var/www/cgi-bin/fig10_11.pl line 14.
Premature end of script headers: fig10_11.pl
...

Check permission of directory cgi-bin
ls -la /var/www/cgi-bin

who is the user of this dir? who started Apache? The user who started Apache
is permitted to access the log file?

The permission from Apache (CGI- Env.) to access a file is different from system's shell!

Read more about System Administration, not just programming.

Best, ulmer

--------
The genius has got 100 scores in programming but nothing about OS, is equals to NULL!
我将cgi-bin目录的权限设为了777,而且我将程序改成open(FILE,"+>>/tmp/log.txt") or die "could not open log.txt: $!";
此外,我将httpd进程杀死,并用root启动该服务,可还是不行.


QUOTE:
could not open log.txt: Permission denied at /var/www/cgi-bin/fig10_11.pl line 14.
Premature end of script headers: fig10_11.pl

已经讲得很清楚了,看看仙子所说的,另外fig10_11.pl开头应该有perl程序路径,你检查一下,比如linux下是#!/usr/bin/perl
用root run apache也不行...会不会没空间了?
df -k 看看....如果是linux df -h也行...
open(FILE,"+>>/tmp/log.txt") 改成
open(FILE,">>/tmp/log.txt");
要读出..另外用个filehandle...读出...

建议你可以先用个简单的CGI..执行看看...有没有办法写入....
然後再试你的程序....
就是这个例子 @ENV{@vars}啥意思