I have a php script that writes to a file. But when I try to actually write to the file I get permission denied. How can I tell what user name I need to add to the file permission in order for the php to write to it?
How can I tell what user name I need to add to the file permission in order for the php to write to it?
ps axu|grep apache|grep -v grep
whatever the file is, or directory for that matter, if apache needs to write to it, it needs to be owned by
www-data, or whatever the user apache is running under on your server. you said in a response that it is
www-data, so as root, you should do
chown www-data filename to change ownership.
i would strongly recommend against changing the permissions to 777, simply because having world readable/writable files and directories on your server can pose some security risks.
ultimately, i would configure your script to write to a set path, then change the ownership of that path to
www-data so future files can be created there if need be, without your interaction being required.
this poses it's own risks, too, as a compromised script can then write and potentially execute whatever it wants from that directory.
as much of a pain as it may be, doing it file by file is less risky.
I tend to just CHMOD the file to 777, assuming you're running on a Unix platform. May not be the most secure thing ever, must gets the job done reliably. I'm sure others will have a better solution though!