11đź‘Ť
New files can be created if the user/group of the parent directory allows it. I believe you either need to change the owner of the directory, or add a group to the directory which includes apache users, or use some advanced technique such as ACL.
To test it out, try the following: Login as root. Switch to apache user. Try to create a file manually. Switch back to root, change the permissions/ownership of the folder, switch to apache user, try again. This should give you some more info about whether the script will fail while trying to create the file.
Finally, it is a bit counterintuitive, make sure that apache user somehow has the execute permission in that directory, otherwise it won’t allow you to cd into that.
Also, I think you will need to set the “s” bit of the directory (chmod g+s
or chmod 2755
etc), so that newly added files inherit the permissions of the directory. Then, you need to make sure that the group’s s bit is set, and the group owns the directory. (or you can set the group of the directory to www-data).