-2

I have set up several projects on my local computer, all projects run in docker containers. Here are the projects:

drupal_projekt_1
drupal_projekt_AB
drupal_projekt_43

For a while I worked on the project drupal_projekt_AB.
After switching to the project drupal_projekt_1 I can't get a database connection in the container!

With command drush status the following output:

wodby@php.container:/var/www/html $ drush status
<em class="placeholder">Notice</em>: Undefined index: DB_HOST in <em class="placeholder">require()</em> (line <em class="placeholder">9</em> of <em class="placeholder">/var/www/html/environments/docker/drupal/settings.local.php</em>). <pre class="backtrace">require(&#039;/var/www/html/environments/docker/drupal/settings.local.php&#039;) (Line: 29)
require(&#039;/var/www/html/docroot/sites/default/settings.php&#039;) (Line: 125)
Drupal\Core\Site\Settings::initialize(&#039;/var/www/html/docroot&#039;, &#039;sites/default&#039;, Object) (Line: 1073)
Drupal\Core\DrupalKernel-&gt;initializeSettings(Object) (Line: 275)
Drupal\Core\DrupalKernel::createFromRequest(Object, Object, &#039;prod&#039;, 1) (Line: 220)
Drush\Boot\DrupalBoot8-&gt;bootstrapDrupalConfiguration(Object, NULL) (Line: 293)
Drush\Boot\BootstrapManager-&gt;doBootstrap(3, 6, NULL) (Line: 493)
Drush\Boot\BootstrapManager-&gt;bootstrapMax(6) (Line: 427)
Drush\Boot\BootstrapManager-&gt;bootstrapToPhaseIndex(-2, Object) (Line: 396)
Drush\Boot\BootstrapManager-&gt;bootstrapToPhase(&#039;max&#039;, Object) (Line: 28)
Drush\Boot\BootstrapHook-&gt;initialize(Object, Object) (Line: 34)
Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher-&gt;callInitializeHook(Object, Object, Object) (Line: 27)
Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher-&gt;initialize(Object, Object) (Line: 145)
Consolidation\AnnotatedCommand\CommandProcessor-&gt;initializeHook(Object, Array, Object) (Line: 289)
Consolidation\AnnotatedCommand\AnnotatedCommand-&gt;initialize(Object, Object) (Line: 221)
Symfony\Component\Console\Command\Command-&gt;run(Object, Object) (Line: 1005)
Symfony\Component\Console\Application-&gt;doRunCommand(Object, Object, Object) (Line: 255)
Symfony\Component\Console\Application-&gt;doRun(Object, Object) (Line: 148)
Symfony\Component\Console\Application-&gt;run(Object, Object) (Line: 118)
Drush\Runtime\Runtime-&gt;doRun(Array, Object) (Line: 49)
Drush\Runtime\Runtime-&gt;run(Array) (Line: 72)
require(&#039;/var/www/html/vendor/drush/drush/drush.php&#039;) (Line: 18)
drush_main() (Line: 143)
require(&#039;phar:///usr/local/bin/drush/bin/drush.php&#039;) (Line: 14)
</pre> Drupal version : 8.9.16
 Site URI       : http://default
 DB driver      : mysql
 DB port        : 3306
 DB username    : drupal
 DB name        : drupal
 PHP binary     : /usr/local/bin/php
 PHP config     : /tmp/aknBEn
 PHP OS         : Linux
 Drush script   : /usr/local/bin/drush
 Drush version  : 9.7.3
 Drush temp     : /tmp
 Drush configs  : /var/www/html/vendor/drush/drush/drush.yml
 Drupal root    : /var/www/html/docroot
 Site path      : sites/default
wodby@php.container:/var/www/html $

If I shut down the container in project drupal_project_1, I switch to project drupal_project_AB, run container up, the command drush status:

wodby@php.container:/var/www/html $ drush st
 Drupal version   : 8.9.16
 Site URI         : http://default
 DB driver        : mysql
 DB hostname      : mariadb
 DB port          : 3306
 DB username      : drupal
 DB name          : drupal
 Database         : Connected
 Drupal bootstrap : Successful
 Default theme    : AB_seven
 Admin theme      : AB_seven
 PHP binary       : /usr/local/bin/php
 PHP config       :
 PHP OS           : Linux
 Drush script     : /usr/local/bin/drush
 Drush version    : 9.7.2
 Drush temp       : /tmp
 Drush configs    : /var/www/html/vendor/drush/drush/drush.yml
 Install profile  : default
 Drupal root      : /var/www/html/docroot
 Site path        : sites/default
 Files, Public    : sites/default/files
 Files, Private   : ../private
 Files, Temp      : /tmp
wodby@php.container:/var/www/html $

I get normal status, all ok.

To test whether the data in the project drupal_project_1 arrives at the configuration information from the file .env at the file /var/www/html/environments/docker/drupal/settings.local.php:

echo "\n\nenv: ".print_r( $_ENV, true )."\n\n";

I did the following output:

env: Array
(
    [SHELL_VERBOSITY] => 0
)

Unfortunately, the variable was empty!

Does anyone have an idea why after switching from project drupal_project_AB to drupal_project_1 I don't get a database connection?

The whole thing happened virtually from one moment to the next



Addendum Yesterday.

I tried the following.
I manually entered the value for DB_HOST in the file /var/www/html/environments/docker/drupal/settings.local.php. The file looks like this for me:

<?php

// Database connection.
$databases['default']['default'] = array (
  'database' => 'database',
  'username' => 'username',
  'password' => 'xxxxxxxx',
  'prefix' => '',
  'host' => 'mariadb',
#  'host' => $_ENV['DB_HOST'],
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);
$settings['memcache']['servers'] = ['memcached:11211' => 'default'];
$databases['migrate']['default'] = $databases['default']['default'];

The drush issue was ok:

Drupal version   : 8.9.16
 Site URI         : http://default
 DB driver        : mysql
 DB hostname      : mariadb
 DB port          : 3306
 DB username      : drupal
 DB name          : drupal
 Database         : Connected
 Drupal bootstrap : Successful
 Default theme    : seven
 Admin theme      : vc_seven
 PHP binary       : /usr/local/bin/php
 PHP config       : /tmp/KLjpFJ
 PHP OS           : Linux
 Drush script     : /usr/local/bin/drush
 Drush version    : 9.7.3
 Drush temp       : /tmp
 Drush configs    : /var/www/html/vendor/drush/drush/drush.yml
 Install profile  : default
 Drupal root      : /var/www/html/docroot
 Site path        : sites/default
 Files, Public    : sites/default/files
 Files, Private   : ../private
 Files, Temp      : /tmp

So far so good.
But when I run:
composer install
composer clearcache
a long message is displayed.
Here is the beginning of the output in a file:
enter image description here

3
  • 1
    >Undefined index: DB_HOST Seems there are placeholders in settings.php instead of actual values. – miststudent2011 Jun 1 at 12:40
  • 1
    You are missing env variables in the other projects. Second, the composer errors are likely from reusing containers across multiple projects where the composer files are likely very different, as are container contents. – Kevin Jun 1 at 14:37
  • The .env file is definitely there. I can look at it via "less", all the data is there, as with other projects. The question is why is it not being read? – webuser57 Jun 2 at 6:37

Your Answer

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

Browse other questions tagged or ask your own question.