Using WP-CLI aliases to switch between multiple WordPress environments safely
Anyone managing several WordPress environments — production, staging, or separate installs for different languages — ends up re-typing SSH connection details and install paths every time they run a command. Building that connection string by hand each time invites mistakes: a copy-paste error, or reusing a stale path, can send a command to the wrong environment entirely. That risk matters most for write commands — bulk plugin updates or database operations — where hitting the wrong target has real consequences. WP-CLI has a built-in feature for exactly this problem: aliases. Note: A WP-CLI "alias" assigns a short name (like @production ) to a set of connection details — an SSH target and a WordPress install path. Once registered, that short name replaces the full connection string on every subsequent command. Where aliases live Aliases are registered in one of two config files: Project-level : wp-cli.yml in the working directory Global : ~/.wp-cli/config.yml in the home directory If the same alias name exists in both, the project-level file takes precedence. If the same environments get used across multiple projects, consolidating aliases in ~/.wp-cli/config.yml keeps things easier to manage. Example registration ( config.yml ): @production : ssh : user@production.example.com:22 path : /var/www/production/wordpress @staging : ssh : user@staging.example.com:22 path : /var/www/staging/wordpress ssh specifies the username, host, and port; path points to the WordPress install directory. This assumes key-based SSH authentication — passwords should never be written into config.yml . If this file is tracked in a repository, an accidental commit turns it into a leak vector for connection details, so keep it in .gitignore , or store it outside the repository in the home directory instead. Calling a single alias Once registered, commands that previously required an ssh login first can run in a single line from your local machine: wp @production plugin list wp @staging plugin