0

I am using Acquia Dev Desktop 2 on my windows 10 PC in order to develop Drupal 8 websites.

As far as I know, every Drupal website requires a connection between its files and the database which is accomplished by using the following code in the setting.php file.

$databases = array(
  'default' => array(
    'default' => array(
      'database' => 'databasename',
      'username' => 'sqlusername',
      'password' => 'sqlpassword',
      'host' => 'localhost',
      'port' => '',
      'driver' => 'mysql',
    ),
  ), 
);

I downloaded Drupal 8 and I imported it in Acquia Dev Desktop 2 using the Import local Drupal site option.

Import new drupal website 1

Import new drupal website 2

The site is correctly imported and installed; a new database has been created.

I cannot see the above database connection code anywhere in the settings.php file.

I noticed, however, that the following code is added to the bottom of the setting.php file.

// <DDSETTINGS>

// Please don't edit anything between <DDSETTINGS> tags.

// This section is autogenerated by Acquia Dev Desktop.

if (isset($_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR']) && file_exists($_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR'] . '/loc_sitename_dd.inc')) {
   require $_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR'] . '/loc_sitename_dd.inc';
}

// </DDSETTINGS>

How does Acquia Dev Desktop 2 create the connection between the site's files and the database without using the common database connection code shown above?

When moving my website from the local development server (Acquia Dev Desktop) to a remote server, I must create a connection to the database. Is it safe to delete the code between the <DDSETTINGS> tags added by Acquia Dev Desktop 2*?

  • It created a file and is requiring it inside settings.php, that’s how it works. Not much more to it. If you delete the statement the local site will no longer connect. – Kevin Sep 12 '18 at 0:01
  • The settings.php stores different configuration values including the database connection. Drupal uses database abstraction layer in its core to connect to several types of databases. That's why you don't see the actual connection code in this file. If you want to understand it more, please refer to api.drupal.org/api/drupal/… – Ismail Cherri Sep 12 '18 at 0:22
  • @kevin is it wise to delete the <DDSETTINGS> tags and replace them by the common database connection code stated in my question on my local site ? I believe the website will work with no errors right ? – Elie Masaad Sep 12 '18 at 0:32
  • 1
    it's wise to delete it if you have a compelling reason to wan to manage that connection yourself, otherwise it's unwise – Clive Sep 12 '18 at 8:50
  • 1
    All you had to do was copy what’s in the file into settings.php. – Kevin Sep 12 '18 at 12:31
0

Thank you all for your help and point me to the right direction !

I will give a detailed explanation because i believe this will benefit plenty of people with common error as mine !

Acquia Dev desktop 2, while creating/importing you website, will create a hidden file (loc_your_site_dd.inc) within its folders where the database connection code is located and then it will refer to that file by adding at the bottom of your setting.php file, few lines of codes similar to:

// <DDSETTINGS> 

// Please don't edit anything between <DDSETTINGS> tags. 

// This section is autogenerated by Acquia Dev Desktop. 

if (isset($_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR']) && file_exists($_SERVER['DEVDESKTOP_DRUPAL SETTINGS_DIR'] . '/loc_sitename_dd.inc')) {
require $_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR'] . '/loc_sitename_dd.inc'; 
} 

// </DDSETTINGS>

Actually this is not a problem and this is how Acquia Dev desktop handle the database connection and other configuration codes.

However, if you are using Drush with your Drupal 8 website but you are using it from a Git Bash instead of using the built-in cmd inside Acquia Dev Desktop, you will be facing a problem similar to this one:

The drush command 'XXX' could not be executed. 
[error] Drush was not able to start (bootstrap) the Drupal database. 

The problem here is that Drush won’t be able to find the which it was added to your sites settings.php file and so it will not be able to find a connection to the database and in result will display the above error.

SOLUTION:

The best solution here is to find the hidden file created by Acquia Dev Desktop which is usually in Windows is located at (*C:\Users\username.acquia\DevDesktop\DrupalSettings*) and copy and pasted all of its contents to your settings.php file and then from inside the settings.php file, delete the code codes added by Acquia Dev desktop.

Doing so, now Drush will be able to find a connection to the database and all will be working as expected.

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.