2

I'm trying out the recommended Hyperlane hosting with Craft CMS. After installing on Hyperlane, I then clone the repo on to my local machine and run 'composer install'. That runs fine, and I create a .env file with my db connection details in it.

What happens next is I go to install on my machine by viewing the admin panel but I get the following:

Database Connection Error – craft\errors\DbConnectException
Craft CMS can’t connect to the database with the credentials in config/db.php.
↵
Caused by: Invalid Configuration – yii\base\InvalidConfigException
Connection::dsn cannot be empty.
in C:\Users\clive\OneDrive\Desktop\repos\projectname\vendor\yiisoft\yii2\db\Connection.php at line 602

If I add the database details to config/db.php myself, it works fine. It just seems to be a problem with fetching them from .env.

I'm using WAMP on Windows and have numerous Craft 3 projects already running. This same project is fine if I install locally from scratch. It's just when I start by cloning from Hyperlane.

Any ideas?

4

Solved. The config/db.php cloned from Hyperlane refers to different env variable names than those used within my .env file. Changing the names in config/db.php solved the issue.

Before:

return [
    'driver' => getenv('DB_DRIVER'),
    'server' => getenv('DB_HOST'),
    'user' => getenv('DB_USER'),
    'password' => getenv('DB_PASSWORD'),
    'database' => getenv('DB_NAME'),
    'schema' => getenv('DB_SCHEMA'),
    'tablePrefix' => getenv('DB_TABLE_PREFIX'),
    'port' => getenv('DB_PORT')
];

After:

return [
    'driver' => getenv('DB_DRIVER'),
    'server' => getenv('DB_SERVER'), // changed
    'user' => getenv('DB_USER'),
    'password' => getenv('DB_PASSWORD'),
    'database' => getenv('DB_DATABASE'), // changed
    'schema' => getenv('DB_SCHEMA'),
    'tablePrefix' => getenv('DB_TABLE_PREFIX'),
    'port' => getenv('DB_PORT')
];
| improve this answer | |
  • Remember to add the file to .gitignore... – Clive Portman Oct 25 '18 at 9:03
  • 1
    Thanks for this! Bloody Hyperlane changing these env variables... cost me ages. – Jay Sep 30 at 15:36

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.