Hello,

I have a script that needs to create folders and append files however, when the folders are created by the script, the user is "nobody" and the files that need to be updated will not due to the following error "[function.file-put-contents]: failed to open stream: Permission denied". I checked get_current_user() and it did show the right user and phpinfo() showed "User/Group: nobody(99)/99".

It seems like the script is being ran by nobody. How would I go about running the script from the user?

Thanks for the help!
Dustin

    When PHP is run as an Apache module (the most common implementation), the scripts are executed by the Apache user, which is typically named "nobody". You may need to follow up the mkdir() call with a [man]chmod/man call to change the permissions on the directory so that it is writable, e.g.:

    chmod('path/to/directory', 0777); // leading zero is important
    

      Thanks for the suggestion NogDog. I actually tried chmod() but since "nobody" owned the file, it did not work. I did just learn about the apache issue you are talking about and it seems like if I run php in cgi or or suphp, the problem would be resolved.

      I attempted to run in both mode and I had different issues with both. With suphp, I get a 500 error. The error logged is "Premature end of script headers:".

      With CGI, the first problem was the save location of sessions. The error is "Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0".

      I will need to look into the problem for one (or both) of them and resolve it. Before I do that, any ideas?

      Thank!

        With the same setup you have (or had if you've already changed it), you could try calling [man]umask/man to set the umask to 0777 before you call mkdir().

        Note that the 0777 mask doesn't mean that the directory won't be owned by "nobody", it just means that the folder's permissions will allow any user to read/write/execute the contents of that folder.

          Write a Reply...