0

I have a folder data, where I programatically create new folders inside it. That's why I want all of these folders to have 777 permissions - because I also create files inside those folders later.

How can I do that?

I tried chmod 777 data, tried chmod -R 777 data - nothing works. Data folder has 777 permissions, but when I create new folder inside, this new folder doesn't have 777 permissions.

How can I solve this?

Mathieu Dumoulin
  • 12,126
  • 7
  • 43
  • 71
khernik
  • 2,059
  • 2
  • 26
  • 51

3 Answers3

1

Use php chmod function:

  chmod($directory, 0777);
chandresh_cool
  • 11,753
  • 3
  • 30
  • 45
  • Oh, one more thing - I use vagrant, so running the code on vagrant, and changing /home/vagrant/data/folder permissions doesnt work. I'd have to change permissions on the synced folder on my host machine - how could I do that? – khernik May 22 '15 at 13:37
  • 1
    At least, this is the right anwser, provided you chould change the code – Mathieu Dumoulin May 22 '15 at 13:39
0

Change the umask either at the php level or apache level

http://php.net/manual/en/function.umask.php Setting the umask of the Apache user

Though its more likely you just want another group to read in, in that case set the group sticky bit on the folder and all files will be created with the same group as the parent

Community
  • 1
  • 1
exussum
  • 18,275
  • 8
  • 32
  • 65
0

It would be helpful to know more about your application, because it is generally a very bad idea to make entire directory structure 777.

Here are some suggestions on how to make things a little more fine-grained:

The 'sticky' bit.

This is what is used in the /tmp folder to allow anyone and everyone to create files, but only the owner or root can access or delete what is created. Here is a link that discusses it.

POSIX Capabilities

Posix Capabilities programmatically elevate your application, giving it a sub-set of root permissions. Capabilities FAQ.

Searching around on these two ideas may give you some more ideas on how you can make your application do what you want, but in a secure way.

Joseph Freivald
  • 396
  • 2
  • 17