1
votes

I'm using Ubuntu 12.04 and Apache2. My perl script is on /usr/lib/cgi-bin and i'm trying to write a file(open ">") to /var/www/my_custom_dir but i get:

Permission denied

If i try to write to the script's directory or any other the error is the same. The permissions seem right. Everything is 755, root owner. I tried to change "my_custom_dir" owner to www-data(apache user), but does not make any difference.

open ( UPLOADFILE, ">$filepath" ) or die "$!"; binmode UPLOADFILE; 
while ( <$file> )  {    print UPLOADFILE $_; } close($file); close UPLOADFILE; }

It "die" on the the first line. The error on log is "Permission denied at /usr/lib/cgi-bin/script.cgi"

2

2 Answers

2
votes

Even if you are starting your cgi-bin in root it is not working ?

Maybe one of directory on your path does not have the right permission applied. A directory has to be +x in order to be openable.

Try to check all the directory that to cgi will have to go through, or lunch the cgi as apache user with "my_custom_dir" in www-data.

0
votes

First of all, setting root as owner of cgi-bin is not a good idea. As you can see, 5=4+0+1, so it gives no write permission to non-owners, only read and execute.

What is the way you changed the owner? Try to do it recursevly (chmod -R)

Also always check if $filepath is correct:

open ( UPLOADFILE, ">$filepath" ) or die "Cannot open $filepath: $!";