16

When I was using apache2 server, setting default umask in /etc/apache2/envvars to 0002 used to solve all my permissions problems. Now that I am trying to setup nginx/php-fpm, I have come across the same problems when files are created with improper permissions.

Is there umask setting in nginx or php-fpm?

jonathancardoso
  • 11,737
  • 7
  • 53
  • 72
Dziamid
  • 11,225
  • 12
  • 69
  • 104

3 Answers3

17

Thanks to Blossoming_Flower's answer and an answer on unix.stackechange...

The best way seems to do as Blossoming _Flower says, but do it with an override file instead of editing a system file that may get replaced by a reinstall/upgrade by your distribution.

To do this you do (I'm on php 7.0 but adjust for your version)

systemctl edit php7.0-fpm.service

which will automatically create (or edit if already exists) a file at /etc/systemd/system/php7.0-fpm.service.d/override.conf.

You can put Blossoming_Flower's suggested content on its own in that file. Systemd will then overwrite the distribution's settings with this one, in effect adding a umask setting.

Then just systemctl daemon-reload && systemctl restart php7.0-fpm and you're done.

artfulrobot
  • 20,637
  • 11
  • 55
  • 81
9

Taken from the other answer's linked question:

if you use systemd [i.e. Ubuntu 16.04], then edit /lib/systemd/system/php5-fpm.service
And edit chapter "Service":

[Service]
UMask=0002
timetofly
  • 2,957
  • 6
  • 36
  • 76
  • 1
    It's best not to change service files themselves. Or the changes would be lost one day, when corresponding package would be updated. Override settings via `/etc/systemd/system/.service.d` [dirs](https://stackoverflow.com/a/37299891/52499). – x-yuri Feb 08 '19 at 20:23
3

I managed to resolve this for myself by adding umask 0002 to /etc/init/php-fpm.conf (not /etc/init.d/php-fpm). See How to trace where php5-fpm umask settings are coming from on ubuntu for an explanation.

Community
  • 1
  • 1
danielmerriott
  • 451
  • 1
  • 3
  • 9