0

I have the following configurations for my Drupal site:

sites/mysite/settings.local.php

$databases['default']['default'] = array(
  'database' => 'mydb',
  'username' => 'root',
  'password' => 'password',
  'prefix' => '',
  'host' => '127.0.0.1',
  'port' => '',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

and for drush, I have : drush/sites/local.site.yml

mysite:
  root: /Users/me/Desktop/Work/Projects/mysite/docroot
  uri: mysite.local

Now when I run drush @local.mysite cr , I am getting:

The specified database connection is not defined: default

If I run drush @local.mysite status, I get:

Drupal version : 9.5.9
Site URI       : http://mysite.local
PHP binary     : /usr/local/Cellar/[email protected]/8.1.19/bin/php
PHP config     : /usr/local/etc/php/8.1/php.ini
PHP OS         : Darwin
Drush script   : /usr/local/bin/drush
Drush version  : 10.6.1
Drush temp     : /tmp
Drush configs  : /Users/me/Desktop/Work/Projects/mysite/vendor/drush/drush/drush.yml
Drupal root    : /Users/me/Desktop/Work/Projects/mysite/docroot
Site path      : sites/default

From this error, I assume that Drush is using the default settings and not the one specified for my site. But I have added the same database configurations to the default settings, which is not working. Also, I have copied the settings.local.php, but it also gives me the same error. I am new to Drupal, and it is an existing codebase that I am working on. It would be very helpful if someone could help me use Drush correctly so I can set up my local development environment.

I have tried to connect to database from the command line, and it is working and also I am able to access the database from PHPMyAdmin

4
  • 1
    And when you run just drush cr? You don't need a Drush yaml for your local site. And are you able to access the site in the browser?
    – leymannx
    Commented Jun 13, 2023 at 6:43
  • It shows The provided host name is not valid for this server when I access the site in a browser. I have configured the trusted_host_patterns to array( '^ mysite\.local$' ), but still, the error persists. Commented Jun 13, 2023 at 9:17
  • It also seems like it is pointing to the wrong folder altogether. The Apache configuration and virtual hosts are correct, but now I get error from another folder, which contains another Drupal site Commented Jun 13, 2023 at 9:54
  • Have you not configured sites.php? You are using multi site by not using sites/default. I’m not sure if that’s intentional. Is there a settings.php in sites/mysite? Does it include settings.local.php? You are doing some unusual things.
    – mona lisa
    Commented Jun 13, 2023 at 11:05

1 Answer 1

1

I assume that the reason you get

The specified database connection is not defined: default

is because sites/mysite/settings.local.php isn't included by any settings.php file.

Look for example at the end of sites/default/settings.php (or sites/default/default.settings.php) to see how the local settings are normally loaded.

3
  • This cannot be the only reason. They put that file in sites/mysite not sites/default.
    – mona lisa
    Commented Jun 13, 2023 at 12:35
  • 1
    I don't disagree, but both you and I know that the name (and folder) for the local settings file is complete arbitrary as long the file actually is included from the used settings.php file ;-)
    – hansfn
    Commented Jun 13, 2023 at 21:20
  • I agree, not loading the settings.local.php in the main settings.php seems the most likely reason here
    – itsandev
    Commented Jun 15, 2023 at 18:06

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.