How to use wp-cli.yml file?

TL;DR:

  1. Run wp version --debug
  2. Check that wp-cli.yml was found
  3. Check that the ABSPATH set by WP-CLI matches the directory where WP is installed
  4. Look at find_wp_root() for hints about why it’s finding the wrong folder

The docs say:

inside the current working directory (or upwards)

…so you should be able to use it in parent directories, not just in the directory where you call wp from. i.e., you should be able to have it several levels above the folder where Core is installed, and then call it from anywhere below the directory where wp-cli.yml is installed [1].

Was wp-cli.yml included?

You can find out by running wp version --debug

  • Found: Debug: Using project config: /var/www/example.localhost/wp-cli.yml (0.012s)
  • NOT Found: Debug: No project config found (0.014s)

Is WP-CLI’s ABSPATH set correctly?

Note: This is the ABSPATH that WP-CLI defines internally, not the one from your wp-config.php

WP-CLI’s internal ABSPATH is what it uses to find WordPress [2, 3], so if it’s wrong then you’ll get the This does not seem to be a WordPress install error.

To find out if it’s wrong, you can run wp version --debug from a few different directories, and look at the ABSPATH output. Does it match the actual path to the folder where Core is installed?

Assuming the path to WP is /var/www/example.localhost/web/wordpress/, then:

  • Correct: Debug: ABSPATH defined: ABSPATH defined: /var/www/example.localhost/web/wordpress/ (0.013s)
  • Incorrect: Debug: ABSPATH defined: /var/www/example.localhost/web/content/plugins/akismet/wordpress/ (0.019s)

Keep in mind that any arguments passed via parameters (e.g., wp --path=foo) will override the values in wp-cli.yml.

Why is ABSPATH wrong?

There are probably lots of different causes for it being wrong, because it depends on how your folder structure is setup, the path defined in wp-cli.yml, etc.

ABSPATH is set to the value of find_wp_root()[4, 5, 6], so that’s where you need to start troubleshooting.

You can read through find_wp_root() and mentally step through the code, looking for clues. If you have WP-CLI installed via composer, then you can also edit Runner.php to add debugging output to find_wp_root(), use Xdebug, etc.

In my case, I had a Bash alias setup for wp that was passing --path to the command, which was overriding the path set in wp-cli.yml, but I’d forgotten about it.

Leave a Comment