2
votes


My PHP-Script creates files and folders.
Like...

mkdir("newfolder");

Those files'/folders' permissions are automatically set to: "755"; the owner and group to: "www-data".

When logged in via sftp, i can't delete/modify those folders, because i'm not the user "www-data" and even though i'm part of the same group, it would probably need "775" permission to allow changes.

So, my question is:

  • How can i make PHP to create those folders with my username as owner?
  • ...or to run as 'myusername' instead of 'www-data'?
  • ...or to set 775 as the default permission?

I'm on Debian, Apache2, PHP 5.6.

1
The preferred way for this is to set the umask of the account www-data, so that files and folders are created with different permissions granting write access to group members. In addition you accept your own user account into the www-data group. - arkascha
Sounds very interesting, from what i've found so far. Thanks! - Elvis

1 Answers

0
votes
mkdir("/path/to/my/dir", 0775);

should do the trick. mkdir also takes more argument such as allowing recursive create etc. check this out http://php.net/manual/en/function.mkdir.php

hope it helps :)