spinupwp-composer-site icon indicating copy to clipboard operation
spinupwp-composer-site copied to clipboard

Consider adding wp-cli.yml

Open mauryaratan opened this issue 2 years ago • 11 comments

Since WP-CLI won't work without wp-cli.yml in place, can you please consider adding it?

cc @polevaultweb

mauryaratan avatar Sep 06 '21 12:09 mauryaratan

@A5hleyRich i'm sure we had this in before, and I seem to remember a convo between us about SpinupWP provisioning that meant we didn't add it?

polevaultweb avatar Sep 06 '21 13:09 polevaultweb

@mauryaratan what doesn't work?

A5hleyRich avatar Sep 21 '21 09:09 A5hleyRich

@A5hleyRich If you run wp commands in the root of the site directory (/site/foo.com/files) you will get the

Warning: No WordPress installation found. If the command 'plugins list' is in a plugin or theme, pass --path=`path/to/wordpress`.

error unless you have the wp-cli.yml file with path: public/wp in it.

We exclude this with gitignore - but not sure why

polevaultweb avatar Sep 23 '21 16:09 polevaultweb

Gotcha. You need to cd into the public dir where the base WP install is. Spinup adds its own wp-cli.yml file, which is why it's not included in the composer template.

A5hleyRich avatar Sep 26 '21 16:09 A5hleyRich

Gotcha. You need to cd into the public dir where the base WP install is. Spinup adds its own wp-cli.yml file, which is why it's not included in the composer template.

I understand now - but this still isn't a great experience for folks not using SpinupWP.

Two options -

  1. SpinupWP adds wp-cli.local.yml instead
  2. SpinupWP only adds wp-cli.yml if it doesn't exist already

Thoughts @A5hleyRich @mauryaratan ?

polevaultweb avatar Sep 27 '21 14:09 polevaultweb

I understand now - but this still isn't a great experience for folks not using SpinupWP.

Given this is a template for Spinup, I don't see why we would handle this.

A5hleyRich avatar Sep 27 '21 15:09 A5hleyRich

It's also a best-practice Composer setup skeleton that we recommend for folks regardless of if it's hosted on SpinupWP.

Is it an issue for us to implement my option 1?

polevaultweb avatar Sep 27 '21 17:09 polevaultweb

Just taking a look at some issues in this repo for my personal development time.

I wanted to add that what's missing here is that if I pull a repo based on this skeleton to work locally, then wp-cli won't work on my local dev unless I add the wp-cli.yml

Is there an option 3? Could we add wp-cli.local.yml to this repo instead of to SpinupWP?

rosswintle avatar Nov 12 '21 16:11 rosswintle

@rosswintle I'll send you some more info

polevaultweb avatar Nov 15 '21 12:11 polevaultweb

OK. So the issue is:

  • This repo wants a wp-cli.yml in it to set the path
  • SpinupWP wants to load ~/.wp-cli/config.yml to ensure that ~/.wp-cli/env.php is loaded

But if we add the first then the second is not loaded at all.

This issue doesn't only apply to this repo, but to others with similar non-standard directory structures such as Bedrock that include a wp-cli.yml

The variables set in ~/wp-cli/env.php are used by the SpinupWP plugin

I do NOT thing there is a way to fix this for all similar starter-kit projects (like Bedrock) without modifying how SpinupWP works. So we'll just have to fix this project.

There are options to merge and inherit values from other WP-CLI config files. I've not used these options, so I'm not quite sure how they work. But the docs say:

# '_' is a special value denoting configuration options for this wp-cli.yml
_:
    # Merge subcommand defaults from the upstream config.yml, instead of overriding
    merge: true
    # Inherit configuration from an arbitrary YAML file
    inherit: prod.yml

So our config could inherit ~/.wp-cli/config.yml. BUT this could have side effects on local dev if you want to override the global config rather than inherit it.

Other approaches:

We could, in this repo, add a composer hook script that does:

if there is a ~/.wp-cli/config.yaml then
  if there is no path in that file then
    add the path to it 
  endif
endif

Or... possibly better

if there is a ~/.wp-cli/env.php then
  require it in our wp-cli.yml
endif

There's trade-offs with all approaches, but I think the last one is my preference.

rosswintle avatar Nov 15 '21 14:11 rosswintle

Seems odd than SpinupWP would encourage a Bedrock setup, CLI usage and similarity between development and production environment, but make it so complex to accomplish all 3.

In theory, it seems straight forward. Add a wp-cli.local.yml file to the root and add path: public/wp into it. The .gitignore ensures it doesn't cause issues with production. However, I just get this now...

Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /public/wp/wp-includes/wp-db.php on line 1753
Error: Error establishing a database connection.

I've taken a look at this... https://jeffreyeverhart.com/2019/02/21/fixing-php-warning-mysqli_real_connect-hy000-2002-with-wp-cli-and-mamp/

I've tried...

127.0.0.1
127.0.0.1:3306
127.0.0.1:8889
127.0.0.1:8890
localhost
localhost:3306
localhost:8889
localhost:8890

My site continues to work with the following, but no luck with WP-CLI.

localhost
localhost:3306
localhost:8889
localhost:8890

My MAMP Local Dev URL used port 8890, hence why I chucked that into the mix.

kwdit avatar May 09 '22 08:05 kwdit