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

I don't know that how to get local Drupal to use settings.local.php?

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

If i create settings.local.php file it still thinks that it as a fresh install and redirects to install.php. So it doesn't recognize that file.

Naturally, all works if I create a settings.php. Can't I just create settings.php for local development and add it into gitignore so it won't get pushed to remote repo?

  • .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? – user1271930 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

When u install drupal u need to copy example.settings.php into settings.php, after drupal installation u need to include following code in settings.php:

if (file_exists(DRUPAL_ROOT . '/' . conf_path() . '/settings.local.php')) { include DRUPAL_ROOT . '/' . conf_path() . '/settings.local.php'; }
  • 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. – user1271930 Oct 22 '19 at 7:49

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.