http://qs321.pair.com?node_id=1189413


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!