# WP Cli question

**URL:** <https://community.localwp.com/t/wp-cli-question/97>\
**Category:** Support\
**Created:** [December 2, 2016, 10:42am UTC](https://community.localwp.com/t/wp-cli-question/97 "2016-12-02T10:42:18Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![lightweb](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/lightweb/32/50_2.png) [@lightweb](https://community.localwp.com/u/lightweb)\
**Post date:** [December 2, 2016, 10:42am UTC](https://community.localwp.com/t/wp-cli-question/97/1 "2016-12-02T10:42:18Z")

</div>

Hi,

First of all - great app. Really works like a charm.  
I only have an issue with WP cli.

I’m not a terminal ninja but i cd ~/Local\ Sites/lightweb-17/app/public/  
but when i run a wp cli command all i get is “Error: Error establishing a database connection”

Any idéa why this is and how i can solove it.  
I have tried to change php version, but it didn’t do the trick.

The site is up and running so the DB clearly works 🙂  
All help highly appreciated.  
Kind regards / Oscar

---

<div class="post-metadata">

**Author:** ![lightweb](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/lightweb/32/50_2.png) [@lightweb](https://community.localwp.com/u/lightweb)\
**Post date:** [December 2, 2016, 1:41pm UTC](https://community.localwp.com/t/wp-cli-question/97/2 "2016-12-02T13:41:23Z")

</div>

Found out i only had to rightklick the server in Local and open in ssh - my bad! 😃

---

<div class="post-metadata">

**Author:** ![zgordon](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/zgordon/32/447_2.png) [@zgordon](https://community.localwp.com/u/zgordon)\
**Post date:** [January 24, 2017, 9:33pm UTC](https://community.localwp.com/t/wp-cli-question/97/3 "2017-01-24T21:33:46Z")

</div>

Would you mind explaining a bit how you solved this? Had the same issue and wasn’t able to work it out.

Thanks!

---

<div class="post-metadata">

**Author:** ![clay](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/clay/32/8248_2.png) [@clay](https://community.localwp.com/u/clay)\
**Post date:** [January 25, 2017, 4:19pm UTC](https://community.localwp.com/t/wp-cli-question/97/4 "2017-01-25T16:19:43Z")

</div>

WP-CLI in Local sits in each site container so you need to right-click on the site inside of Local then go to `Open Site SSH`. Once it opens the Terminal window you can immediately type `wp`

If you want to use WP-CLI outside of the container then you’ll need to create a wp-cli.yml file that points to the Remote Host and Port shown in the Database tab of the site.

---

<div class="post-metadata">

**Author:** ![zgordon](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/zgordon/32/447_2.png) [@zgordon](https://community.localwp.com/u/zgordon)\
**Post date:** [February 27, 2017, 2:49am UTC](https://community.localwp.com/t/wp-cli-question/97/5 "2017-02-27T02:49:28Z")

</div>

Aw, perfect 🙂 Found that!

---

<div class="post-metadata">

**Author:** ![tedw](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/tedw/32/4907_2.png) [@tedw](https://community.localwp.com/u/tedw)\
**Post date:** [August 3, 2017, 2:41pm UTC](https://community.localwp.com/t/wp-cli-question/97/6 "2017-08-03T14:41:22Z")

</div>

@clay Could you please post an example of what the wp-cli.yml should look like? I’m having trouble getting this to work. I installed wp-cli using Composer and am trying to use the “post-update-cmd” hook to run a wp-cli command. Thanks!

---

<div class="post-metadata">

**Author:** ![clay](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/clay/32/8248_2.png) [@clay](https://community.localwp.com/u/clay)\
**Post date:** [August 4, 2017, 7:15pm UTC](https://community.localwp.com/t/wp-cli-question/97/7 "2017-08-04T19:15:57Z")

</div>

Hi @tedw,

If you’re wanting to run WP-CLI from your computer and not inside the site container, you can try the following:

1. Open `wp-config.php` in `app/public`
2. Add a conditional for the `DB_HOST` constant. The value needs to be whatever the “Remote Host” of the database is followed by the “Remote Port” so it’ll look something like:

```auto
/** MySQL hostname */
if ( defined( 'WP_CLI' ) && WP_CLI ) {
	define( 'DB_HOST', '192.168.65.100:4006' );
} else {
	define( 'DB_HOST', 'localhost' );
}

```

---

<div class="post-metadata">

**Author:** ![tedw](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/tedw/32/4907_2.png) [@tedw](https://community.localwp.com/u/tedw)\
**Post date:** [August 4, 2017, 8:33pm UTC](https://community.localwp.com/t/wp-cli-question/97/8 "2017-08-04T20:33:23Z")

</div>

Ah, makes sense. Thanks, @clay!

---

<div class="post-metadata">

**Author:** ![efc](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/efc/32/1446_2.png) [@efc](https://community.localwp.com/u/efc)\
**Post date:** [August 31, 2017, 4:18pm UTC](https://community.localwp.com/t/wp-cli-question/97/9 "2017-08-31T16:18:40Z")

</div>

Hi all, thanks for this thread! I could still use some help getting WP-CLI to work from outside the Local container. I’ve done the `wp-config.php` setup as recommended by @clay, but I have no idea where to put the `wp-cli.yml` file that was mentioned or what to put in it. Can anyone share more details?

I have been able to edit my regular `config.yml` for WP-CLI, but my entries there look like this:

```auto
@shortcut:
   ssh: user@host

```

While I can get the `host` from the Site Setup tab in Local, I cannot find any hint of a user. When I use Local’s built in SSH feature (which is really a `docker -exec` it appears), it pops me into root. I could try `root@host` but I have no idea what the Local root password is, and using root seems excessive (the web server files seem to be owned by 501, but that user does not even have a name, much less a password).

If someone could provide a clear example of how to set this up, I would really appreciate it. Thanks!

---

<div class="post-metadata">

**Author:** ![architchandra](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/architchandra/32/5090_2.png) [@architchandra](https://community.localwp.com/u/architchandra)\
**Post date:** [October 2, 2017, 5:02pm UTC](https://community.localwp.com/t/wp-cli-question/97/10 "2017-10-02T17:02:45Z")

</div>

I am also facing a problem with this. I have made the edits according to the comment by @clay but I’m getting an error connecting to the database. As there was no mention about how to set up the wp-cli.yml (or I just completely missed it), I couldn’t set it up. It would be really nice if you could help a little bit on this. Thanks!

![09](https://sea1.discourse-cdn.com/flex019/images/transparent.png)

---

<div class="post-metadata">

**Author:** ![architchandra](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/architchandra/32/5090_2.png) [@architchandra](https://community.localwp.com/u/architchandra)\
**Post date:** [October 2, 2017, 5:10pm UTC](https://community.localwp.com/t/wp-cli-question/97/11 "2017-10-02T17:10:53Z")

</div>

Okay, please scratch that. I was being non-observant and did not replace the original define(‘DB\_HOST’, ‘localhost’) statement with what @clay mentioned. It looks like it’s working now. Thanks!

Just one more question though. I am still a beginner so please bear a trivial question. You mentioned a .yml file but the the problem got fixed by just modifying the wp-config.php file. Where does the yml file play a part? Or am I just missing something?

---

<div class="post-metadata">

**Author:** ![davidperez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/davidperez/32/8525_2.png) [@davidperez](https://community.localwp.com/u/davidperez)\
**Post date:** [October 30, 2019, 9:40am UTC](https://community.localwp.com/t/wp-cli-question/97/12 "2019-10-30T09:40:59Z")

</div>

> [@clay](#):
>
> The value needs to be whatever the “Remote Host” of the database is followed by the “Remote Port”

Where is that button?

---

<div class="post-metadata">

**Author:** ![hexagongirl](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/hexagongirl/32/8816_2.png) [@hexagongirl](https://community.localwp.com/u/hexagongirl)\
**Post date:** [November 27, 2019, 4:33pm UTC](https://community.localwp.com/t/wp-cli-question/97/13 "2019-11-27T16:33:31Z")

</div>

> [@clay](#):
>
> The value needs to be whatever the “Remote Host” of the database is followed by the “Remote Port”

@clay - thanks; is this still valid with Local Lightening? (I’m running 5.0.7). I’ve seen a screenshot showing Remote Host and Port in the Database tab for a site, but these aren’t present in my install. Where would I find these values in 5.0.7?

---

<div class="post-metadata">

**Author:** ![localjo](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/localjo/32/10282_2.png) [@localjo](https://community.localwp.com/u/localjo)\
**Post date:** [April 24, 2020, 6:06pm UTC](https://community.localwp.com/t/wp-cli-question/97/14 "2020-04-24T18:06:06Z")

</div>

These aren’t present in my install either. How can we find the remote host and port now?

 ![Screen Shot 2020-04-24 at 6.40.43 PM](https://us1.discourse-cdn.com/flex019/uploads/lwpforums/original/2X/4/4fa9d178b756dfda8665877b7271d73404bf08a2.png)

---

<div class="post-metadata">

**Author:** ![circlecube](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/circlecube/32/4580_2.png) [@circlecube](https://community.localwp.com/u/circlecube)\
**Post date:** [July 21, 2020, 7:39pm UTC](https://community.localwp.com/t/wp-cli-question/97/15 "2020-07-21T19:39:27Z")

</div>

Yes, good question, this no longer works with Local version 5.x.x (Lightning) as the host and port values have been removed and replaced with a socket value. Any way to get the host/port values returned so we can continue to use this software?

---

<div class="post-metadata">

**Author:** ![afragen](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/afragen/32/31_2.png) [@afragen](https://community.localwp.com/u/afragen)\
**Post date:** [July 21, 2020, 8:29pm UTC](https://community.localwp.com/t/wp-cli-question/97/16 "2020-07-21T20:29:31Z")

</div>

Go to Preferences \> Advanced and select ‘localhost’ for Router Mode.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/system/32/1_2.png) [@system](https://community.localwp.com/u/system)\
**Post date:** [October 19, 2020, 8:29pm UTC](https://community.localwp.com/t/wp-cli-question/97/17 "2020-10-19T20:29:35Z")

</div>

Closed on October 19, 2020, 8:29pm UTC

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