Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Opening files to write in browser returns Permission denied

by scorpio17 (Canon)
on May 03, 2017 at 16:00 UTC ( [id://1189413]=note: print w/replies, xml ) Need Help??


in reply to Opening files to write in browser returns Permission denied

You don't want a file with 666 permissions - that means it's world writable: anyone can modify it (very poor security). The first thing you need to do is figure out what user the web server is running as. I think the default user for apache on debian is www-data. If you're using apache, the main config file should be located here:
/etc/apache2/apache2.conf
Inside there should be something like this:

User www-data Group www-data

If it's something different (i.e., "nobody" or "apache" - just make a note of whatever it is).

Your cgi script will be running on the server as that user (not as you), so that user needs write permission to the file you want it to create. Also - the containing directory must be writable by that user (have write and execute permission).

So you need to do something like this on the server (don't type the inline comments):

cd /path_of_your_choice_goes_here
sudo mkdir webapp_output_files     # create directory to hold your files - name it whatever you like
sudo chown root:www-data           # set user:group ownership - note that the group should be the same group that the webserver runs as
sudo chmod 775                     # note: this gives group write permission

Now any user belonging to the www-data group should be able to write files into that directory. Run your script and see if that works. Make sure your writing the file into the webapp_output_files directory (or whatever you chose to call it). The file create should have owner:group of www-data:www-data, and the permission bits should default to either 664 or 644, depending on your umask setting.

I hope that helps. Good luck!

Replies are listed 'Best First'.
Re^2: Opening files to write in browser returns Permission denied
by Anonymous Monk on May 03, 2017 at 16:12 UTC
    Maybe this is overkill?
      Overkill? Well, having locks and ignition keys for our cars might be overkill, too, because a simple switch would suffice. Imagine: never again having a problem about forgotten or lost keys. The problem is that then anyone could drive away with your car, just as 666 allows anyone to write anything into your file…

        But world writable is a lie, it doesn't mean I can write to it

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1189413]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-03-29 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found