# Db\_host configuration

**URL:** <https://community.kinsta.com/t/db-host-configuration/1597>\
**Category:** Application Support\
**Created:** [July 6, 2022, 1:32am UTC](https://community.kinsta.com/t/db-host-configuration/1597 "2022-07-06T01:32:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ms-bris](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@ms-bris](https://community.kinsta.com/u/ms-bris)\
**Post date:** [July 6, 2022, 1:32am UTC](https://community.kinsta.com/t/db-host-configuration/1597/1 "2022-07-06T01:32:26Z")

</div>

Hi there.

After installing WP-CLI, running any commands was met with `Error: Error establishing a database connection.`

In _wp-config.php_ I changed `define( 'DB_HOST', 'devkinsta_db' );` to `define( 'DB_HOST', '127.0.0.1:<PORT NUMBER>' );`. This fixed the problem with WP-CLI and I was able to successfully run commands, however, it then broke the DB connection when I try to access content through the WP Dashboard.

What is the correct configuration to permit both WP-CLI and regular database functionality to both work?

Many thanks for your help.

---

<div class="post-metadata">

**Author:** ![Kevin](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/kevin/32/808_2.png) [@Kevin](https://community.kinsta.com/u/Kevin)\
**Post date:** [July 6, 2022, 4:57pm UTC](https://community.kinsta.com/t/db-host-configuration/1597/2 "2022-07-06T16:57:52Z")

</div>

Hi @ms-bris, thanks for reaching out! Can you detail how you installed WP-CLI and where? I will try to reproduce your process/issue. It sounds like a host routing issue.

By the way, the `devkinsta_fpm` container already has WP-CLI installed, although you would have to run it as root form there which may not be ideal.

---

<div class="post-metadata">

**Author:** ![ms-bris](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@ms-bris](https://community.kinsta.com/u/ms-bris)\
**Post date:** [July 6, 2022, 10:44pm UTC](https://community.kinsta.com/t/db-host-configuration/1597/3 "2022-07-06T22:44:58Z")

</div>

Thanks @Kevin.

We’re developing using the Sage 10 starter theme with a WordPress instance spun up with DevKinsta. There is some reference in the Sage 10 documentation to using WP-CLI and we thought we would try and integrate it’s use on this project and WP projects more generally.

I’m in an OS X environment with PHP 8.0 and WordPress 6.0. I followed the install steps on [wp-cli.org](https://wp-cli.org) for a global install, specifically using the following commands to complete the install -

```auto
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp cli update

```

I’m not sure if it’s relevant but there is some dev URL config in theme’s [bud.config.js file](https://github.com/roots/sage/blob/main/bud.config.js)

Thanks again Kevin and let me know if you require any further info.

---

<div class="post-metadata">

**Author:** ![Kevin](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/kevin/32/808_2.png) [@Kevin](https://community.kinsta.com/u/Kevin)\
**Post date:** [July 6, 2022, 11:20pm UTC](https://community.kinsta.com/t/db-host-configuration/1597/4 "2022-07-06T23:20:26Z")

</div>

So you have it installed globally right in Terminal? I’ve looked it over again and I think the only convenient way will be fore you to run the command in the FPM container. So from terminal run this command:

`docker exec -u www-data -it devkinsta_fpm bash`

Then you just `cd` to your desited site’s home directory and test any wp-cli command. It should route the db\_host correctly from within the container if you leave it as “devkinsta\_db.”

---

<div class="post-metadata">

**Author:** ![ms-bris](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@ms-bris](https://community.kinsta.com/u/ms-bris)\
**Post date:** [July 7, 2022, 11:37am UTC](https://community.kinsta.com/t/db-host-configuration/1597/5 "2022-07-07T11:37:59Z")

</div>

Thanks Kevin.

That’s correct - it was globally installed in Terminal.

I ran that command from terminal and `cd`’d in the home directory. I ran the same WP command I used when I had set the DB\_host as `DB_HOST', '127.0.0.1:<PORT NUMBER>` and successfully ran the command earlier. What I got back this time was -

```auto
PHP Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.2". You are running 7.4.29. in /www/kinsta/public/<theme-name>/wp-content/plugins/acorn/vendor/composer/platform_check.php on line 24
Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.2". You are running 7.4.29. in /www/kinsta/public/<theme-name>/wp-content/plugins/acorn/vendor/composer/platform_check.php on line 24

```

`DB_HOST` has been left as `devkinsta_db`. A check of PHP versions says I’m running 8.0.18.

Any thoughts?

Thanks again for your help.

---

<div class="post-metadata">

**Author:** ![Kevin](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/kevin/32/808_2.png) [@Kevin](https://community.kinsta.com/u/Kevin)\
**Post date:** [July 7, 2022, 4:19pm UTC](https://community.kinsta.com/t/db-host-configuration/1597/6 "2022-07-07T16:19:14Z")

</div>

That’s odd. Can you check the PHP version with `php -v` ?  
Is that what’s returning 8.0.18? I believe that container uses php 7.4.29 by default. Can you share the command that you are trying to run? Feel free to public message it to me as well if it has any private information.

And just to confirm, does a basic wp-cli command also return that error? `wp help`

---

<div class="post-metadata">

**Author:** ![ms-bris](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@ms-bris](https://community.kinsta.com/u/ms-bris)\
**Post date:** [July 7, 2022, 10:12pm UTC](https://community.kinsta.com/t/db-host-configuration/1597/7 "2022-07-07T22:12:40Z")

</div>

Thanks @Kevin. Making sense now I think.

- The container instance is running PHP 7.4.29;
- The DevKinsta instance install was with PHP 8.0;
- The command used is `wp acorn make:composer ExampleComposer`;
- The command `wp help` returns the same error;

The Acorn install I used was to run on PHP version 8.0 (from [here](https://github.com/roots/acorn/releases/tag/v2.0.6)).

---

<div class="post-metadata">

**Author:** ![Kevin](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/kevin/32/808_2.png) [@Kevin](https://community.kinsta.com/u/Kevin)\
**Post date:** [July 7, 2022, 11:02pm UTC](https://community.kinsta.com/t/db-host-configuration/1597/8 "2022-07-07T23:02:28Z")

</div>

Okay thanks for that @ms-bris  
This is an interesting puzzle. I’m going to try to try to reproduce your setup to see what’s possible with DevKinsta as-is. I know there’s a solution somewhere. Usually wp cli works by default in that container. I’m not sure why it isn’t working for you/why you have a php version requirement.

I’m going to do some testing tomorrow and consult with our Devs then get back to you!

---

<div class="post-metadata">

**Author:** ![ms-bris](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@ms-bris](https://community.kinsta.com/u/ms-bris)\
**Post date:** [July 8, 2022, 1:21am UTC](https://community.kinsta.com/t/db-host-configuration/1597/9 "2022-07-08T01:21:29Z")

</div>

Above and beyond @Kevin - thankyou!

---

<div class="post-metadata">

**Author:** ![Kevin](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/kevin/32/808_2.png) [@Kevin](https://community.kinsta.com/u/Kevin)\
**Post date:** [July 8, 2022, 7:41pm UTC](https://community.kinsta.com/t/db-host-configuration/1597/10 "2022-07-08T19:41:49Z")

</div>

I think I’ve figured this out @ms-bris. So this is going back to your original issue with installing wp-cli globally and getting the database connection error:

1. In terminal, use the command `hostname -I` to get your IP address.
2. In wp-config.php, set your `DB_HOST` to ipaddress:dbport (123.1.2.3:15101)

The main idea is to not use localhost, 127.0.0.1 or devkinsta\_nginx as the db\_host. The first two won’t work because of the loopback in `/etc/hosts` on the Docker containers and `devkinsta_nginx` will only get routed correctly as a host when used within the Docker containers (that’s why it wasn’t working with global wp-cli).

Your machine’s IP address/port is the most direct way to connect to the database and won’t run into any hosts file conflicts. Please let me know if this doesn’t work for you, though. I was only able to test with Windows/Linux but the same idea should apply to Mac.

---

<div class="post-metadata">

**Author:** ![ms-bris](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@ms-bris](https://community.kinsta.com/u/ms-bris)\
**Post date:** [July 11, 2022, 7:00am UTC](https://community.kinsta.com/t/db-host-configuration/1597/11 "2022-07-11T07:00:15Z")

</div>

@Kevin it looks to be working! How wonderful.

I tripped my self up because I was using my external IP. Once the internal IP was used it worked. Also, ` hostname -I` doesn’t work for some reason (might be a Mac thing) but there are other commands / avenues to get the details.

Thanks for your patience and direction! Very much appreciated.
