During a project installation always fails to install correctly.

Let me clarify this is how it should work: Drupal changes the chmod of settings.php to 777 and then applies changes for the drupal system, then executes all hook_install_tasks in all .profile files and then drupal changes the chmod of settings.php to read only (644 i think).

What happens on macbook is that after the drupal changes are applied to settings.php drupal changes the chmod to 644 before executing all the hook_install_tasks which is wrong because it can't edit the settings.php file anymore. But the hooks are required for the project to run properly so now need to be manually executed.

Here is the console

 [notice] Starting Drupal installation. This takes a while.
 [notice] Performed install task: install_select_language
 [notice] Performed install task: install_select_profile
 [notice] Performed install task: install_load_profile
 [notice] Performed install task: install_verify_requirements
 [notice] Performed install task: install_settings_form
 [notice] Performed install task: install_verify_database_ready
 [notice] Performed install task: install_base_system
 [notice] Performed install task: install_bootstrap_full
 [notice] Performed install task: install_profile_modules
 [notice] Performed install task: install_profile_themes
 [notice] Performed install task: install_install_profile
 [notice] Performed install task: install_configure_form
 [warning] file_put_contents(sites/default/settings.php): Failed to open stream: Operation not permitted SettingsEditor.php:174
In SettingsEditor.php line 175:
  Failed to modify 'sites/default/settings.php'. Verify the file permissions.                                                                              

Does anyone have a solution for me?

  • What is "it" in "is that after the drupal changes it changes the chmod to 644"?
    – mona lisa
    Oct 3, 2023 at 12:43
  • @cilefen clarified some more in the original post
    – Tazio
    Oct 3, 2023 at 12:47
  • What does "project doesn't work" mean, technically? There are assumptions and other statements here but no technical detail on what is actually going wrong.
    – mona lisa
    Oct 3, 2023 at 13:00
  • @cilefen sorry for the back and forth, i don't know any details of the error nor the in and outs of the system. I also couldn't find anything online of this error so idk if it's just my machine
    – Tazio
    Oct 3, 2023 at 13:19
  • 3
    Unfortunately, there isn't enough information in this question to get an answer. Evidently there is some kind of a profile, with hooks of some kind, which are trying to edit the settings.php file. But we haven't been shown them and we don't know what they are.
    – mona lisa
    Oct 3, 2023 at 14:26

2 Answers 2


You can use

$settings['skip_permissions_hardening'] = TRUE;

in your settings.php and Drupal will never manage file permissions

  • 2
    That may be done with an informed understanding of the risks.
    – mona lisa
    Oct 3, 2023 at 16:38
  • Sadly this wouldn't work since there isn't a settings.php before you install the project. There is a default.settings.php but when added it removes it automatically
    – Tazio
    Oct 11, 2023 at 12:21
  • DDEV solves this problem for you.
    – Kevin
    Oct 11, 2023 at 13:56

Worked on Vanish's answer and ended up using form_alter hook on install_settings_form (SiteSettingsForm.php) to write the settings into the file.


 * Implements hook_form_FORM_ID_alter().
function indicia_profile_form_install_settings_form_alter(array &$form, FormStateInterface $form_state): void {
  $form_state->loadInclude('indicia_profile', 'inc', 'includes/form_alter.install_settings');
  indicia_profile_install_settings_form_alter($form, $form_state);


function indicia_profile_install_settings_form_alter(array &$form, FormStateInterface $form_state): void {
  array_unshift($form['actions']['save']['#submit'], 'indicia_profile_install_settings_form_submit');

function indicia_profile_install_settings_form_submit(array &$form, FormStateInterface $form_state): void {
  if ($form_state->getValue('isDevelopment')) {
    $settings['settings']['skip_permissions_hardening'] = (object) [
      'value' => TRUE,
      'required' => TRUE,

    SettingsEditor::rewrite(DRUPAL_ROOT . '/sites/default/settings.php', $settings);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.