0
  1. Download Drupal 8
  2. Copy the default.settings.php file to settings.php
  3. Modify the settings.php file by adding the definition of the database connections

    $databases['default']['default'] = array (
    'database' => getenv('MYSQL_DATABASE'),
    'username' => getenv('MYSQL_USER'),
    'password' => getenv('MYSQL_PASSWORD'),
    'prefix' => '',
    'host' => getenv('MYSQL_HOSTNAME'),
    'port' => getenv('MYSQL_PORT'),
    'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
    'driver' => 'mysql',
    

    );

  4. Execute drush si or install Drupal from the browser

  5. Check the settings.php file: It will contain the database connections data twice

    $databases['default']['default'] = array (
      'database' => getenv('MYSQL_DATABASE'),
      'username' => getenv('MYSQL_USER'),
      'password' => getenv('MYSQL_PASSWORD'),
      'prefix' => '',
      'host' => getenv('MYSQL_HOSTNAME'),
      'port' => getenv('MYSQL_PORT'),
      'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
      'driver' => 'mysql',
    );
    $databases['default']['default'] = array (
      'database' => 'drupal',
      'username' => 'root',
      'password' => 'pass',
      'prefix' => '',
      'host' => '127.0.0.1',
      'port' => '3306',
      'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
      'driver' => 'mysql',
    );
    

Is it a normal behavior? If it is an issue, how do I prevent it?

I tried with chmod 444 settings.php, but drush si still modifies it. Even if I removed the getenv() call and manually inserted, the database connections values are still duplicated.

  • I found that If I set the variable $settings['hash_salt'] previously before executing drush si or web installation then It doesn't append another database variable. – SkyRar Sep 30 '18 at 4:21
  • You should not edit the settings.php file before installing Drupal. Yes, it's the normal behavior, since appending an array definition to a PHP file (like the settings.php file) it's easier and quicker than searching the array definition in the file and replacing it. After all, if you define a variable twice, PHP will consider only the last definition. Just keep in mind that the settings.php file is a PHP file and it is parsed as PHP file. – kiamlaluno Sep 30 '18 at 11:24
  • @kiamlaluno Thanks. But if it is a normal behaviour to make process faster then it should append 'n' times if I execute 'n' times of drush si. But It always override the second database array i.e always there exists two database variables not more than two. – SkyRar Sep 30 '18 at 11:59
  • I think that Drush, like Drupal, notices when the settings.php has been already edited from the installer, so it doesn't do anything the second time you run drush si. In fact, when you want to reinstall Drupal, the procedure is to delete the settings.php file and copy it from the default.settings.php file. – kiamlaluno Sep 30 '18 at 19:30

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.