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.

  • Do you have the correct credentials stored in the .env file? – Tim Strawbridge Mar 3 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 Mar 4 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 Mar 4 at 13:23
  • Hi Oli, I cleared caches from the admin (not cli). – Martin Mar 4 at 17:33
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

| improve this answer | |
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>"
| improve this answer | |

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.