I set the
SETGID bit on
files directory so that any new directories or files created by drupal/php inside sites/default/files will take the group ownership of parent directory i.e here
files. But I figured out Drupal clears/unset the SETGID bit for newly created directories like css, php, js etc.
I checked with a simple script if it is an issue with PHP-FPM, but it was not. I think Drupal does chmod in his side while creating new dirs which turns out to SETGID bit to be unset automatically.
I found there is one SO question related to Wordpress ( https://superuser.com/questions/1271465/force-wordpress-php-to-respect-setgid-bit-when-creating-new-files-directories )
How to reproduce ?
chown :deploy web/sites/default/files chmod g+s web/sites/default/files ls -al web/sites/default/files drwxrwxr-x 2 www-data deploy 4096 Nov 7 08:41 css drwxrwxr-x 2 www-data deploy 4096 Nov 7 08:32 js drwxrwxrwx 3 www-data deploy 4096 Nov 7 08:32 php
Expected result (x bit should be replaced by s for group)
ls -al web/sites/default/files drwxrwsr-x 2 www-data deploy 4096 Nov 7 08:41 css drwxrwsr-x 2 www-data deploy 4096 Nov 7 08:32 js drwxrwsrwx 3 www-data deploy 4096 Nov 7 08:32 php
Is it an issue of Drupal 8 or a knowing behavior ? Any workaround for this issue ?
However I found something inside settings.php regarding chmod. I tried to uncomment and set my required permission like
2770 (Where 2 is SETGID bit) but it doesn't help.
/** * Default mode for directories and files written by Drupal. * * Value should be in PHP Octal Notation, with leading zero. */ $settings['file_chmod_directory'] = 02770; # $settings['file_chmod_file'] = 0664;
It seems like Drupal 7 obeys setgid rule ( https://www.drupal.org/docs/7/install/step-3-create-settingsphp-and-the-files-directory ) But why doesn't work for me. Doesn't it work for Drupal 8 ?
I found a strange behaviour setgid works for the directory
Php/twig i.e all the dir/files inside php directory owned by group
deploy. But inside css and js dir it doesn't obey the rule.