1

I've hit a snag while trying to move my Craft 3 project from MAMP to DDEV. First I installed a new DDEV project using the php project type and MySQL 8.0 for the database. Then I imported the database to DDEV. Then I updated my .env variables with the following values:

DB_DRIVER="mysql"
DB_SERVER="db"
DB_PORT="3306"
DB_DATABASE="db"
DB_USER="db"
DB_PASSWORD="db"
DB_SCHEMA=public
DB_TABLE_PREFIX=

After that I launched the project in the browser, navigated to the control panel, and got hit with this error:

No database has been selected yet.

I was able to successfully connect to the database using a plain PHP test script, but Craft can't for some reason.

Aside from checking and re-checking the .env settings I'm not exactly sure how else to troubleshoot this. The fact that Craft seems to think this is an installation issue is probably a clue, though I'm not really sure how.

I ran php craft setup/db-creds and here's what I got back:

Which database driver are you using? (mysql or pgsql) [mysql] 
Database server name or IP address: [db] 
Database port: [3306] 
Database username: [db] 
Use the password provided by $DB_PASSWORD? (yes|no) [yes]:no
Database password: 
Database name: [db] 
Database table prefix: 
Testing database credentials ... failed: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known

Here's what my config/db.php file looks like:

return [
    'dsn' => getenv('DB_DSN'),
    'user' => getenv('DB_USER'),
    'password' => getenv('DB_PASSWORD'),
    'schema' => getenv('DB_SCHEMA'),
    'tablePrefix' => getenv('DB_TABLE_PREFIX'),
];

Here's my ddev describe output:

┌───────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Project: my-project ~/My/Project/Location/my-project https://my-project.ddev.site  │
│ Docker platform: docker-desktop                                                                   │
│ Router: traefik                                                                                   │
├──────────┬──────┬──────────────────────────────────────────────────────────┬──────────────────────┤
│ SERVICE  │ STAT │ URL/PORT                                                 │ INFO                 │
├──────────┼──────┼──────────────────────────────────────────────────────────┼──────────────────────┤
│ web      │ OK   │ https://my-project.ddev.site                        │ php PHP8.1           │
│          │      │ InDocker: web:443,80,8025                                │ nginx-fpm            │
│          │      │ Host: 127.0.0.1:55134,55133                              │ docroot:'dist'       │
│          │      │                                                          │ Mutagen enabled (ok) │
│          │      │                                                          │ NodeJS:18            │
├──────────┼──────┼──────────────────────────────────────────────────────────┼──────────────────────┤
│ db       │ OK   │ InDocker: db:3306                                        │ mysql:8.0            │
│          │      │ Host: 127.0.0.1:55132                                    │ User/Pass: 'db/db'   │
│          │      │                                                          │ or 'root/root'       │
├──────────┼──────┼──────────────────────────────────────────────────────────┼──────────────────────┤
│ Mailpit  │      │ Mailpit: https://my-project.ddev.site:8026          │                      │
│          │      │ `ddev launch -m`                                         │                      │
├──────────┼──────┼──────────────────────────────────────────────────────────┼──────────────────────┤
│ All URLs │      │ https://my-project.ddev.site,                       │                      │
│          │      │ https://127.0.0.1:55134,                                 │                      │
│          │      │ http://my-project.ddev.site, http://127.0.0.1:55133 │                      │
└──────────┴──────┴──────────────────────────────────────────────────────────┴──────────────────────┘

Here's the full Craft error log:

yii\base\InvalidConfigException: No database has been selected yet. in /var/www/html/craft/vendor/craftcms/cms/src/controllers/InstallController.php:320
Stack trace:
#0 /var/www/html/craft/vendor/craftcms/cms/src/controllers/InstallController.php(73): craft\controllers\InstallController->_checkDbConfig()
#1 [internal function]: craft\controllers\InstallController->actionIndex()
#2 /var/www/html/craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#3 /var/www/html/craft/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#4 /var/www/html/craft/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('index', Array)
#5 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(295): yii\base\Module->runAction('install/index', Array)
#6 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(562): craft\web\Application->runAction('install/index')
#7 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(203): craft\web\Application->_processInstallRequest(Object(craft\web\Request))
#8 /var/www/html/craft/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#9 /var/www/html/dist/index.php(21): yii\base\Application->run()
#10 {main}
2
  • 1
    What does your config/db.php file look like?
    – Brad Bell
    Oct 17 at 16:24
  • Edited the question to include it.
    – kmgdev
    Oct 17 at 17:38

1 Answer 1

1

It looks like you’re specifying a DB_DSN in your config/db.php file, but your .env file isn’t defining that variable.

You either need to specify the full DB_DSN string in your .env file or update your config/db.php file to pull in the individual database connection settings from your .env file.

1
  • Yup, that was it. For some reason updating db.php to use DB_SERVER didn't work but adding DB_DSN="mysql:host=db;port=3306;dbname=db;" to .env did.
    – kmgdev
    Oct 18 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.