Search code examples
phpumask

How to set umask for www-data user?


I am currently running Apache/2.4.10 (Debian Jessie) with PHP 7.0.6 fpm

All points that now I need to add umask 0002 into php-fpm.conf, so that www-data user will create files with rw-rw-r permissions.


Solution

  • I hope this will work, Please try this way

    Manually edit /etc/systemd/system/multi-user.target.wants/ php7.0-fpm.service file and add UMask=0002 line inside [Service] section.

    Previously, it was like this.

    enter image description here

    then

    Run command systemctl daemon-reload

    then

    Run command systemctl restart php7.0-fpm.service

    Now the service file looks like this:

    [Unit]
    Description = The PHP FastCGI Process Manager
    After = network.target
    
    [Service]
    Type = notify
    PIDFile = /var/run/php/php7.0-fpm.pid 
    ExecStartPre = /usr/lib/php/php7.0-fpm-checkconf
    ExecStart = /usr/sbin/php-fpm7.0 --nodaemonize --fpm-config /etc/php/7.0/fpm/php-fpm.conf
    ExecReload = /bin/kill -USR2 $MAINPID
    ; Added to set umask for files created by PHP
    UMask = 0002
    
    [Install]
    WantedBy = multi-user.target
    

    NB : You can not use systemctl edit php7.0-fpm.service command as edit option was introduced in systemctl version 218 but Debian 8 ships with version 215.