1

I have a flask application that creates directory with this code:

if not os.path.exists(target_path):
    os.makedirs(target_path)

With the created directory the default permission is 0755, and the owner and group is _www. So, only the owner can write in the directory.

I always have to modify the permission manually to 0775 to make some files in it.

enter image description here

How to make the default directory permission as 0775? I use apache for web server.

prosseek
  • 182,215
  • 215
  • 566
  • 871

2 Answers2

2

This has something to do with Apache setup.

For Mac:

  1. Open /System/Library/LaunchDaemons/org.apache.httpd.plist
  2. Add <key>Umask</key> and <integer>002</integer>
  3. Restart with sudo apachectl restart

I found the solution from this site, for linux I guess Setting the umask of the Apache user can give some hints.

Community
  • 1
  • 1
prosseek
  • 182,215
  • 215
  • 566
  • 871
  • 1. since El Capitan you can't edit certain system files / directories (including System/Library) even as root: https://support.apple.com/en-us/HT204899 To be able to write you have to disable csrutil: https://apple.stackexchange.com/a/208481/258780 2. adding the suggested changes to the plist didn't work for me - apache continuous to write files and directories in 755/644 mode... – FullStack Alex Dec 16 '19 at 04:06
  • Ok, I've figured it out: the and tags have to go inside the top level tag. I've put it first within the EnvironmentVariables' tag. Then I had to "sudo apachectl stop" and then "sudo apachectl start" instead of simply restart. – FullStack Alex Dec 16 '19 at 05:58
0

Change the code to

if not os.path.exists(target_path):
    os.makedirs(target_path, mode=0775)
kums
  • 2,661
  • 2
  • 13
  • 16