# Setting database in config to run wp commands

**URL:** <https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358>\
**Category:** Application Support\
**Created:** [April 26, 2024, 11:55pm UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358 "2024-04-26T23:55:16Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![jesswcd](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/jesswcd/32/3330_2.png) [@jesswcd](https://community.kinsta.com/u/jesswcd)\
**Post date:** [April 26, 2024, 11:55pm UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358/1 "2024-04-26T23:55:16Z")

</div>

Hi guys I am used to Local WP but am trying to make the switch so we can host our sites on Kinsta. My only drawback is I can’t run the `wp acorn` commands from my terminal in my theme file as it says it can’t make a database connection. I need this to use the log1x/acf-composer package. On Local WP I change the wp-config database to reference the php version from ‘details’ and point direct to the database.

Does anyone have a way to ensure I can run acorn commands and connect to the kinsta db?

---

<div class="post-metadata">

**Author:** ![Andrew](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/andrew/32/2792_2.png) [@Andrew](https://community.kinsta.com/u/Andrew)\
**Post date:** [April 27, 2024, 8:58pm UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358/3 "2024-04-27T20:58:44Z")

</div>

Hi @jesswcd! Welcome to the Kinsta community!

Thank you for reaching out to us on the forums! I want to let you know we are investigating into this matter, and are attempting to replicate this issue on our end. We will be providing an update as soon as possible once we have more details to share.

In the meantime, if you do have any further information you’d like to share please feel free to reply!

Best regards

---

<div class="post-metadata">

**Author:** ![Andrew](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/andrew/32/2792_2.png) [@Andrew](https://community.kinsta.com/u/Andrew)\
**Post date:** [April 29, 2024, 1:46am UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358/5 "2024-04-29T01:46:37Z")

</div>

Hi @jesswcd!

We want to thank you for your patience while we investigated further into this matter. We have been performing testing internally to replicate the issue. After further investigation and tests we do see that it is possible to replicate this when the database configuration within the **.env** file is incorrect.

You will need to ensure that the database credentials are updated to match the expected values to establish a connection with the DevKinsta database Docker container. Please review your .env file database credentials to ensure that the username is set to “root” and that the password matches the value generated during the devkinsta\_db container creation. A quick way to acquire this password would be to create a new site in DevKinsta and view the wp-config.php file created. This password can be used on your existing site with the Acorn installation.

You will also need to ensure that the **DB\_HOST** value is set to **devkinsta\_db** in the .env file.

Please let us know if this helps, or if you continue to have any difficulty with running the WP-CLI Acorn commands. We are standing by and more than happy to help!

Best regards

---

<div class="post-metadata">

**Author:** ![jesswcd](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/jesswcd/32/3330_2.png) [@jesswcd](https://community.kinsta.com/u/jesswcd)\
**Post date:** [April 29, 2024, 6:46pm UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358/6 "2024-04-29T18:46:41Z")

</div>

Hi @Andrew , thanks for looking into this. I do not have a .env I have the wp\_config setting the host. Am I doing something wrong there? For terminal I am using Warp from the theme to run wp acorn. Composer is installed in the theme as well as I am not using Bedrock, just the plain Sage 10 theme.

```auto
/** Database username */
define( 'DB_USER', 'root' );

/** Database password */
define( 'DB_PASSWORD', '[PASSWORD]' );

/** Database hostname */
define( 'DB_HOST', 'devkinsta_db' );

```

```auto
wp acorn make:component Separator
Warning: mysqli_real_connect(): php_network_getaddresses: getaddrinfo for devkinsta_db failed: nodename nor servname provided, or not known in /Users/jess/DevKinsta/public/rhubarb-and-lavender/wp-includes/class-wpdb.php on line 1987
Warning: mysqli_real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo for devkinsta_db failed: nodename nor servname provided, or not known in /Users/jess/DevKinsta/public/rhubarb-and-lavender/wp-includes/class-wpdb.php on line 1987
Error: `php_network_getaddresses: getaddrinfo for devkinsta_db failed: nodename nor servname provided, or not known`
Error establishing a database connection
This either means that the username and password information in your `wp-config.php` file is incorrect or that contact with the database server at `devkinsta_db` could not be established. This could mean your host’s database server is down.

Are you sure you have the correct username and password?
Are you sure you have typed the correct hostname?
Are you sure the database server is running?

If you are unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress support forums. `php_network_getaddresses: getaddrinfo for devkinsta_db failed: nodename nor servname provided, or not known`

```

---

<div class="post-metadata">

**Author:** ![jackirish](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/jackirish/32/1361_2.png) [@jackirish](https://community.kinsta.com/u/jackirish)\
**Post date:** [April 29, 2024, 9:59pm UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358/7 "2024-04-29T21:59:31Z")

</div>

Hi @jesswcd ! 👋 That error reads like the database name is not correct for some reason 🤔

Are you able to check the `/Library/Application Support/DevKinsta/config.json` file, and confirm that the database name listed there is the same as the one inside wp-config.php?

---

<div class="post-metadata">

**Author:** ![jesswcd](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/jesswcd/32/3330_2.png) [@jesswcd](https://community.kinsta.com/u/jesswcd)\
**Post date:** [April 30, 2024, 3:58pm UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358/8 "2024-04-30T15:58:26Z")

</div>

Hi @jackirish there is no DevKinsta directory in my application support. DevKinsta is in applications but there is nothing in /Library/Application Support/DevKinsta/config.json I have tried uninstalling and reinstalling and nothing changed.

---

<div class="post-metadata">

**Author:** ![Alessandro](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/alessandro/32/2310_2.png) [@Alessandro](https://community.kinsta.com/u/Alessandro)\
**Post date:** [May 3, 2024, 10:39am UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358/9 "2024-05-03T10:39:40Z")

</div>

Hey @jesswcd 👋,  
I am not able to replicate the issue on my side:

 ![Screenshot 2024-05-03 at 11.38.37](https://us1.discourse-cdn.com/flex020/uploads/kinsta/original/2X/2/2d6d253a7b8e4a4a1ee8e7403371605baf54d8a9.png)

Can you please clarify the following:

1. From which terminal are you running the command?
2. Does any other wpcli command that makes checks to the db work? Please try `wp db check --allow-root` and let us know if you receive the same error

---

<div class="post-metadata">

**Author:** ![jesswcd](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/jesswcd/32/3330_2.png) [@jesswcd](https://community.kinsta.com/u/jesswcd)\
**Post date:** [May 3, 2024, 9:24pm UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358/10 "2024-05-03T21:24:49Z")

</div>

HI @Alessandro just to note, it is not within bedrock this is just the Sage theme on it’s own within the wp-content themes directory.

1. I am running it through the Warp terminal.

2. 

 ![image](https://us1.discourse-cdn.com/flex020/uploads/kinsta/original/2X/d/dc5035d4693a13efff54ced97a1dee1f94bcae87.png)

 ![image](https://us1.discourse-cdn.com/flex020/uploads/kinsta/original/2X/d/d446e12927efb0bea5ad0c83aaf0c3867d1025d6.png)

---

<div class="post-metadata">

**Author:** ![Alessandro](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/alessandro/32/2310_2.png) [@Alessandro](https://community.kinsta.com/u/Alessandro)\
**Post date:** [May 7, 2024, 11:26am UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358/11 "2024-05-07T11:26:39Z")

</div>

Can you please try the same commands but within docker? Open docker, select the fpm container, then click on the terminal tab. Move to the right path of your installation and then perform the desired command (being sure to use --allow-root)

---

<div class="post-metadata">

**Author:** ![jesswcd](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/jesswcd/32/3330_2.png) [@jesswcd](https://community.kinsta.com/u/jesswcd)\
**Post date:** [May 8, 2024, 5:33pm UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358/12 "2024-05-08T17:33:35Z")

</div>

> [@Alessandro](#):
>
> wp db check --allow-root

Hi @alessandro.promo

It works when I am in the fpm container. But it doesn’t have tab completion/highlighting etc. and slows me down a lot being in there and takes me out of my normal work process to enter. into docker. Is there a way I can make this work from my own terminal?

---

<div class="post-metadata">

**Author:** ![Adrian\_L](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/adrian_l/32/2810_2.png) [@Adrian\_L](https://community.kinsta.com/u/Adrian_L)\
**Post date:** [May 9, 2024, 6:17am UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358/13 "2024-05-09T06:17:43Z")

</div>

HI @jesswcd

Can you try the following:

From within your Warp terminal, log in to the Docker container using `docker exec -u www-data -it devkinsta_fpm bash`. After that, navigate to your theme directory and try running the WP CLI commands again.

I tried it on my end, and I can run the wp cli command just fine.  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/kinsta/original/2X/2/23f1ce6351b044e1102826b8e17daf4dd0230d6e.png)

Let us know how it goes!

---

<div class="post-metadata">

**Author:** ![jesswcd](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/jesswcd/32/3330_2.png) [@jesswcd](https://community.kinsta.com/u/jesswcd)\
**Post date:** [May 10, 2024, 3:11pm UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358/14 "2024-05-10T15:11:39Z")

</div>

> [@Alessandro](#):
>
> wp db check --allow-root

That worked!

Now that we know how to grab access is there anyway around logging into the container? Do we have any idea why it doesn’t connect through Warp?

Thank you!!

---

<div class="post-metadata">

**Author:** ![jesswcd](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/jesswcd/32/3330_2.png) [@jesswcd](https://community.kinsta.com/u/jesswcd)\
**Post date:** [May 10, 2024, 3:17pm UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358/15 "2024-05-10T15:17:14Z")

</div>

Interestingly enough, when I try and run the ‘wp acorn’ commands that I really need to run for my theme to work, it thinks I am on php 7.4.33 even though my site is on 8.2. I am guessing that is what the docker is on?

 ![Screenshot 2024-05-10 at 9.13.08 AM](https://us1.discourse-cdn.com/flex020/uploads/kinsta/original/2X/b/b278a6512f4367f4cab4c750592f8999e275bf58.jpeg)  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/kinsta/original/2X/7/7d30a74592178e4db0fb05967f35eb18a3519df5.png)

php -v in warp says php 8.3

 ![image](https://us1.discourse-cdn.com/flex020/uploads/kinsta/original/2X/a/a98d14342918ec7e0705b3891367444b7e79142c.png)

So unfortunately, it really doesn’t work! Any ideas?

---

<div class="post-metadata">

**Author:** ![Alessandro](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/alessandro/32/2310_2.png) [@Alessandro](https://community.kinsta.com/u/Alessandro)\
**Post date:** [May 10, 2024, 3:45pm UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358/16 "2024-05-10T15:45:25Z")

</div>

Most probably wpcli is using a different PHP version right now. What’s the output of `wp cli info --allow-root` ?

---

<div class="post-metadata">

**Author:** ![Adrian\_L](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/adrian_l/32/2810_2.png) [@Adrian\_L](https://community.kinsta.com/u/Adrian_L)\
**Post date:** [May 13, 2024, 4:53am UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358/17 "2024-05-13T04:53:20Z")

</div>

Hello @jesswcd,

I have checked and found that wp cli is using PHP 7.4 by default in DevKinsta. However, I was able to change it to use a different PHP version (8.2) by changing the symlink of PHP in the **/etc/alternatives** directory inside the **devkinsta\_fpm** container. I suggest that you try doing the same from your end to see if it works. 🙂

 ![image](https://us1.discourse-cdn.com/flex020/uploads/kinsta/original/2X/7/70a64060e7b7dfa73406e2bed22d2d3f02b49d1d.jpeg)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/kinsta/original/2X/8/80f8c4e56fecc02327a0964e6bf63a716483529f.png) [@system](https://community.kinsta.com/u/system)\
**Post date:** [May 16, 2024, 12:56am UTC](https://community.kinsta.com/t/setting-database-in-config-to-run-wp-commands/3358/18 "2024-05-16T00:56:06Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
