0

I'm facing issues on inheriting the parent permissions for the folders created by PHP script which is executed by the server.

I've created the deployer user, added to www-data group and set the initial folder and file config like below.

usermod -a -G www-data deployer
chown -R www-data:www-data /var/www
chmod -R 0775 /var/www
find /var/www -type d -exec chmod 2775 {} +;   
find /var/www -type f -exec chmod 0664 {} +;

Edited the php5-fpm.conf file like below with adding umask 0002.

umask 0002
pre-start exec /usr/lib/php5/php5-fpm-checkconf
respawn
exec /usr/sbin/php5-fpm --nodaemonize --fpm-config /etc/php5/fpm/php-fpm.co

And this is the related part of my /etc/php5/fpm/pool.d/www.conf, nginx user is also www-data.

user  = www-data
group = www-data

listen = /var/run/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0666

I've executed the setfacl command as below:

setfacl -Rm u:www-data:rwx,u:deployer:rwx,g:www-data:rwx /var/www/site/storage
setfacl -Rdm u:www-data:rwx,u:deployer:rwx,g:www-data:rwx /var/www/site/storage

However, when a PHP script, executed by the server, tries to create a folder within the storage folder which was created by the deployer user, newly created folders don't inherit the parent permissions.

drwxrwsr-x+ deployer www-data storage
drwxr-sr-x+ www-data www-data storage-cache-folder 
drwxr-sr-x+ www-data www-data storage-cache-folder-subfolder

What am I missing?

1
  • Of course you can do this with umask as well, just make sure you implement umask before the creation of files, in your php script
    – ostendali
    Oct 12, 2015 at 15:43

1 Answer 1

1

I am not a PHP developer but as sysadmin I can tell you that there is workaround to fix the issue you are having. In order to give specific permission to dynamically created files by PHP you can either set the default permission using ACLs or using PHP chmod:

   chmod($file, 0777); for example (change it whatever perm you'd like)

   setfacl -d -m o::rwx /var/www/site/storage (or add the group/user you'd like)

The ACL -d option will set that directory as default provided/given permissions so anything created there would have that default permission.

Check here for better understanding about what you are after:

   http://php.net/manual/en/function.umask.php
4
  • The PHP script creates folders with the chmod 777 already within the system.
    – Burak
    Oct 12, 2015 at 15:51
  • have you tried setting default ACLs as per my first suggestion?
    – ostendali
    Oct 12, 2015 at 16:13
  • however, it is all well explained here: php.net/manual/en/function.umask.php
    – ostendali
    Oct 12, 2015 at 16:21
  • I've already tried the setting umask within the PHP script too, and it didn't work either, thus I don't want to cast rwx for others per you suggested, I don't understand why the system wide umask 0002doesn't work for the folders that are being cast chmod 777 or setfacl don't affect.
    – Burak
    Oct 12, 2015 at 16:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .