handbook/guides/sharing-wp-cli-packages.md
2026-06-02 10:46:48 +02:00

29 lines
2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Sharing WP-CLI Packages
By default, WP-CLI places [installed packages](https://developer.wordpress.org/cli/commands/package/) in `~/.wp-cli/packages/`, a hidden subdirectory for the users home directory.
Because the home directory is different for each user, this naturally means each system user will have a separate directory of installed packages. If you have multiple active shell users on a server, and want to share installed WP-CLI packages between them, there are a couple of supported ways to do this.
## `WP_CLI_PACKAGES_DIR` environment variable
To override the directory WP-CLI uses for installed packages, provide a `WP_CLI_PACKAGES_DIR` environment variable. If you wish for multiple users to share the same packages directory, you can simply provide the same `WP_CLI_PACKAGES_DIR` environment variable for each user.
vim /etc/environment
export WP_CLI_PACKAGES_DIR=/usr/local/lib/wp-cli-packages
Similarly, you can make sure the directory is only writable by a specific user to make packages available to all users, but only installable by the specific user.
Its worth noting the `WP_CLI_PACKAGES_DIR` environment variable *overrides* WP-CLIs default behavior of loading packages installed in the users home directory. If you want to support both, youll need to take the second approach.
### Composer project in a shared directory
WP-CLIs installed packages directory is simply a Composer project under the hood. Given this architecture, you can create your own Composer project in an arbitrary directory, and load it into scope using WP-CLIs `--require=<path>` flag.
First, create your Composer project.
$ mkdir /usr/local/lib/wp-cli-packages
$ cd /usr/local/lib/wp-cli-packages
$ composer init -n --name=runcommand/wp-cli-packages -s=dev
$ composer require wp-cli/server-command
Now, once your Composer project has a dependency or two, you can use `wp --require=<path/to/autoload>` (or the equivalent `config.yml` statement) to load the packages into WP-CLI.