Deploying to Kinsta, error establishing a database connection

I having been following my hosting company’s guide to deploying Trellis/Bedrock: https://kinsta.com/blog/bedrock-trellis/ but when to run ansible-playbook deploy.yml -e env=staging -e site=mysite.com --limit=kinsta_staging It runs to a certain point and then keeps giving me this error:

TASK [deploy : WordPress Installed?] ********************************************************************************************************************************************************************************
System info:
  Ansible 2.5.4; Darwin
  Trellis version (per changelog): "Verify `wp-cli.phar` checksum"
---------------------------------------------------
non-zero return code
Error: Error establishing a database connection. This either means that the
username and password information in your `wp-config.php` file is incorrect
or we can’t contact the database server at `localhost`. This could mean your
host’s database server is down.
fatal: [kinsta_staging]: FAILED! => {"changed": false, "cmd": ["wp", "core", "is-installed", "--skip-plugins", "--skip-themes", "--require=/www/myusername/public/shared/tmp_multisite_constants.php"], "delta": "0:00:00.354424", "end": "2018-06-14 22:11:36.560825", "failed_when_result": true, "rc": 1, "start": "2018-06-14 22:11:36.206401", "stderr_lines": ["Error: Error establishing a database connection. This either means that the username and password information in your `wp-config.php` file is incorrect or we can’t contact the database server at `localhost`. This could mean your host’s database server is down."], "stdout": "", "stdout_lines": []}

Any ideas on what I am missing?

It looks like you’re missing your database information. The linked article describes what you need:

Next, open trellis/group_vars/staging/vault.yml for editing by running ansible-vault edit group_vars/staging/vault.yml.

We need to add db_user, db_name, and db_password to env. We also need to add vault_ansible_ssh_pass. You can find the values for these on the main info screen for your site in the MyKinsta dashboard.

Yup, I got all those steps covered. I added my staging values to trellis/group_vars/staging/vault.yml by running ansible-vault edit group_vars/staging/vault.yml.

I would probably double-check all my DB values to make sure they don’t contain spaces, are being parsed properly, don’t contain values that could be processed somehow, etc. The step where it’s failing is in roles/deploy/hooks/finalize-before.yml if you want to check it out, but It looks pretty straightforward. Unless this is a Kinsta-environment-specific problem, I’m not sure what else it could be. @ben might have some more insight. You might also contact Kinsta support if you haven’t already.

If you look at the .env file on your deployed site, do the values inside match what Kinsta has for your database settings?

When I look at .env on my staging instance, it loads all the right values except for DB_USER. It is using the value from my dev environment for DB_USER.

I found it - group_vars/staging/vault.yml was missing db_user :man_facepalming:

1 Like