4

I couldn't find answer from previous questions nor drupal.org/pantheon.io.

There isn't a settings.php if I clone the repository from pantheon.io nor a settings.local.php.

If I create a settings.local.php file, it still thinks it's a fresh install and redirects to install.php, which means it doesn't recognize that file.

How do I use the settings.local.php file?

Naturally, all works if I create a settings.php file.

Can't I just create settings.php for the development site and add a reference to it in the .gitignore file to avoid it will be pushed on the remote repository?

3
  • .gitignore in Drupal core already ignores settings.php file by default. If the repo doesn't have a settings.php, it should be safe to create one. It will not be added to the repo on git add.
    – AjitS
    May 8 '17 at 6:35
  • Okay, I'll try to keep that in mind. However, it is still a question that how settings.local.php could be used? May 8 '17 at 10:59
  • You will need to still edit settings.php to write a include statement for the settings.local.php as described on the answer.
    – AjitS
    May 9 '17 at 6:04
5

When installing Drupal, you need to copy the example.settings.php file in settings.php. After Drupal is installed, you need to include the following code in the settings.php file.

if (file_exists(DRUPAL_ROOT . '/' . conf_path() . '/settings.local.php')) {
  include DRUPAL_ROOT . '/' . conf_path() . '/settings.local.php';
}
2
  • This answer may be outdated. The combination DRUPAL_ROOT and conf_path() may return the wrong value and then prevents the settings local file from being loaded. @mbomb007's answer below seems to fix this.
    – leymannx
    Jun 21 '19 at 13:40
  • And to include this it is supposed to be appended to settings.php? If it has same variables that is in settings.php then it would override them to match local preferences. Oct 22 '19 at 7:49
2

There is an active issue for this that has already been committed to 8.x and 9.x, and it's being backported to 7.x. It adds the code in settings.php to include settings.local.php.

The code in the patch makes some improvements on the code in the other answer.

/**
 * Include a local settings file if it exists.
 */
$local_settings = dirname(__FILE__) . '/settings.local.php';
if (file_exists($local_settings)) {
  include $local_settings;
}

See Add inclusion of a settings.local.php file in settings.php.

Additional Notes:

  • The file name "settings.local.php" is not consistent with other filenaming standards used. There is an open issue to rename the file to "local.settings.php" in the future (probably 9.x).

  • If you use Git, make sure your local settings file is excluded in your .gitignore file.

  • Here is a helpful guide on configuring settings files and file permissions: Configuring settings.php and settings.local.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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