1

For quite a long time i've updated and amended Craft by taking a copy of the files and database (.zip) from the live server, making the updates/changes/amendments locally and then transferring everything back (.zip).

Just recently i've had a couple of instances where i've made amendments and updates to an older site (Craft 3.1x to 3.4x) and everything has been fine locally. I then deploy the updated version back to the live environment and immediately get the error Craft can’t connect to the database with the credentials in craft/config/db.php.

I know this is a familiar error for some but i've only recently started seeing it. I've spent a long time looking for and trying fixes but nothing seems to work for me!?

Mac OS Catalina MAMP Pro 5.7 PHP 7.2.22 MySQL 5.7.26

Like I say, this is actually quite a new problem for me and I don't know what has changed? Any help is very much appreciated.

4
  • Do you have the correct credentials stored in the .env file? Commented Mar 3, 2020 at 19:59
  • Hi Tim, yes all correct and checked by a number of different people. We even have our hosting provider support team looking into it and they can't work it out either. Also, one of the other businesses in our building has just told me they too are experiencing the same problem!
    – Martin
    Commented Mar 4, 2020 at 11:36
  • Have you tried clearing your caches (./craft clear-caches/all) or specifically empty your storage/runtime folder? If you move everything as you described, some stuff could be cached from your local environment.
    – Oli
    Commented Mar 4, 2020 at 13:23
  • Hi Oli, I cleared caches from the admin (not cli).
    – Martin
    Commented Mar 4, 2020 at 17:33

2 Answers 2

1

From Craft Support: Assuming the credentials in your .env are correct on that site, could you run ./craft clear-caches/all (or manually empty your web/cpresources and storage/runtime

1

Have a look at your .env file on the production system and your config/db.php file your repo. Craft has changed the way db access data is stored and must now be provided as a DSN

This is now config/db.php

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

So make sure you have DB_DSN set in your .env file:

DB_DSN="mysql:host=<dbhost>;port=<dbport>;dbname=<db>"

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.