wp-cli-wordpress

WP-CLI Install Step by Step for WordPress

WP-CLI is the command line interface for WordPress. You can update plugins, configure multisite installations, and much more, without using a web browser.

Continuous maintenance is made possible by:

automattic
bluehost
pantheon
siteground-logo
wpengine
Cloudways-Logo-r22222

The current stable version is 2.5.0. To stay up to date, follow @wpcli on Twitter or sign up for email updates. See the roadmap for an overview of what’s planned for upcoming releases.

Usage

WP-CLI provides a command line interface for many actions you can perform on the WordPress desktop. For example, wp plugin install –activate (doc) allows you to install and activate a WordPress plugin:

$ wp plugin install user-switching –activate Installing

User Switching (1.0.9) Downloading install package from https://downloads.wordpress.org/plugin/user-switching.1.0.9.zip… Unpacking the package… Installing the plugin…

The plugin was installed successfully. Activating ‘user-switching’… Plugin ‘user-switching’ activated. Success: Installed 1 of 1 plugin.

WP-CLI also includes commands for many things you can’t do on the WordPress desktop. For example, wp transient delete –all (doc) allows you to delete one or all transient data:

$ wp transient delete –all

Success: 34 transients deleted from the database.

For a more complete introduction to using WP-CLI, read the quick start guide. Or, catch up with shell friends to learn about command line utilities.

Already comfortable with the basics? Go to the full list of commands for detailed information on managing themes and plugins, importing and exporting data, performing database search and replace operations, and more.

Installation

Downloading the Phar archive is our recommended installation method for most users. If needed, see also our documentation about alternative installation methods (Composer, Homebrew, Docker).

Before installing WP-CLI, make sure that your environment meets the minimum requirements:

  • UNIX-like environment (OS X, Linux, FreeBSD, Cygwin); limited support in Windows environment
  • PHP 5.6 or later
  • WordPress 3.7 or later. Versions prior to the latest version of WordPress may have degraded functionality.

Once you have verified the requirements, download the wp-cli.phar file using wget or curl :

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Next, check the Phar archive to verify that it is working:

php wp-cli.phar –info

To use WP-CLI from the command line by typing wp, make the file executable and move it somewhere in your PATH. For example:

chmod +x wp-cli.phar

sudo mv wp-cli.phar /usr/local/bin/wp

If WP-CLI was installed correctly, you should see something like this when you run: wp –info:

$ wp –info

OS: Linux 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64

Shell: /usr/bin/zsh

PHP binary: /usr/bin/php

PHP version: 8.0.5

php.ini used: /etc/php/8.0/cli/php.ini

MySQL binary: /usr/bin/mysql

MySQL version: mysql Ver 8.0.23-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

SQL modes: WP-CLI

root dir: /home/wp-cli/ WP-CLI

vendor dir: /home/wp-cli/vendor

WP_CLI phar path: WP-CLI packages

dir: /home/wp-cli/.wp-cli/packages/ WP-CLI

global config: WP-CLI project config: /home/wp-cli/wp-cli.yml WP-CLI version: 2.5.0

Upgrade

You can update WP-CLI with wp cli update (doc), or by repeating the installation steps.

If WP-CLI is owned by root or another system user, you will need to run sudo wp cli update.

Want to live life on the edge? Run wp cli update –nightly to use the latest nightly build of WP-CLI. A nightly build is more or less stable enough for you to use in your development environment and always includes the latest and greatest WP-CLI features.

Autocomplete with the tab key

WP-CLI also comes with an autocompletion script with the tabulator for Bash and ZSH. Just download wp-completion.bash and use the source command from ~/.bash_profile:

source /FULL/PATH/TO/wp-completion.bash

Don’t forget to run source ~/.bash_profile afterward.

If you use the zsh shell, you may need to load and start bashcompinit before using the source command. Put the following in your .zshrc:

autoload

bashcompinit

bashcompinit source /RUTA/COMPLETA/HASTA/wp-completion.bash