Skip to main content

WP-CLI YAML Configuration

In this lesson you will learn how to configure WP-CLI using YAML files. You'll see where these files are loaded from, how to set global or per-project defaults, and how to disable destructive commands like db drop, db reset, and site empty so they can't be run by accident.

Disabled commands

WP-CLI usually works out of the box and doesn't require any additional configuration. However, it is a very powerful tool, and with great power comes great responsibility. Using WP-CLI you can easily:

  • Drop your WordPress database
  • Reset or truncate your WordPress database
  • Empty a site in a WordPress multisite network

When working with production WordPress websites, these destructive commands are likely to be unintentional, copy/pasted from the wrong place, run in the wrong directory, or for the wrong site.

I prefer having these three commands disabled for all my WP-CLI needs, and I'm happy to jump through some hoops in the rare occasion when I actually need to drop the database or reset a site.

We can disable certain WP-CLI commands using a configuration file.

WP-CLI YAML

WP-CLI supports a wide range of global parameters which can be configured in a YAML file. The YAML files are loaded in the following order:

  1. wp-cli.local.yml in the current directory or its parents
  2. wp-cli.yml in the current directory or its parents
  3. ~/.wp-cli/config.yml

This allows us to have per-project or per-website configuration, as well as a safe configuration in the user's home directory to fall back on. Note that command-line arguments and flags always override whatever is in a configuration file, except disabled_commands, which is only available via a configuration file.

This article is for premium members only. One-time payment of $96 unlocks lifetime access to all existing and future content on wpshell.com, and many other perks.