Make your "local" machine work as intended, and maintain the security of your live site.
Given that you should only be using composer require
on your local machine, this approach will fix the issue on your local machine. The default .gitignore will limit the change to your local.
Don't make this change to settings.php, since you don't want to affect other instances, especially PROD.
Steps
- enable settings.local.php (here are the instructions from the docblock in settings.local.php):
* To activate this feature, copy and rename it such that its path plus
* filename is 'sites/default/settings.local.php'. Then, go to the bottom of
* 'sites/default/settings.php' and uncomment the commented lines that mention
* 'settings.local.php'.
*
* If you are using a site name in the path [... read about exceptions in file]
set file permissions to allow user and group to write to the file on your local machine:
$ chmod ug+w {name_of_docroot}/sites/default
How this approach matches up with the established community approach
By default, settings.local.php contains the following line:
$settings['skip_permissions_hardening'] = TRUE;
This line tells Drupal not to reset permissions on the default
folder only on your local, and allows you to work more smoothly with composer on your local without loosening permissions on any other copy of the codebase.