Drupal - composer require fails because it can't delete default.services.yml

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

  1. 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]
  1. 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.


This command will fix it temporarily:

chmod u+w web/sites/default

But Drupal will harden permission again soon. To turn it off add this to settings.php:

$settings['skip_permissions_hardening'] = TRUE;

Source: https://www.drupal.org/docs/develop/using-composer/starting-a-site-using-drupal-composer-project-templates#s-troubleshooting-permission-issues-prevent-running-composer


I think you need to use

chmod ug+w web/sites/default

Without the g (group write permission) twig can't create it's tmp directories in files/php/twig and the site will throw a warning.

Tags:

Composer