spinupwp / spinupwp-composer-site

A WordPress site setup using Composer that is primed and ready to be hosted using SpinupWP.
https://spinupwp.com/
110 stars 21 forks source link

Consider adding wp-cli.yml #11

Open mauryaratan opened 3 years ago

mauryaratan commented 3 years ago

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

cc @polevaultweb

polevaultweb commented 3 years ago

@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?

A5hleyRich commented 3 years ago

@mauryaratan what doesn't work?

polevaultweb commented 3 years ago

@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

A5hleyRich commented 3 years ago

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.

polevaultweb commented 3 years ago

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 ?

A5hleyRich commented 3 years ago

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.

polevaultweb commented 3 years ago

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?

rosswintle commented 2 years ago

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?

polevaultweb commented 2 years ago

@rosswintle I'll send you some more info

rosswintle commented 2 years ago

OK. So the issue is:

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.

kwdit commented 2 years ago

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.