WP-CLI Complete Tutorial: How to Install It, Understand It, and Use the Most Important wp Commands
If you manage WordPress sites regularly, WP-CLI can save a ridiculous amount of time. Instead of clicking through the dashboard for every plugin, theme, database, or user task, you can manage WordPress directly from the terminal with the wp command. WP-CLI is the official command-line tool for WordPress, and its goal is to offer a CLI equivalent for the actions you normally do in wp-admin. (Make WordPress)
This tutorial walks you through the full basics: what WP-CLI is, how to install it, how to verify it, how its commands are structured, the main command groups you should know, and the practical commands that are most useful in real WordPress operations and troubleshooting. Everything here is based on the official WP-CLI and WordPress documentation. (Make WordPress)
What is WP-CLI?
WP-CLI is the official command-line interface for WordPress. It lets you do administrative and development tasks from the shell, including downloading WordPress core, creating wp-config.php, installing plugins, activating themes, listing users, running database operations, doing search-replace, and much more. (Make WordPress)
In practice, the command style is simple:
wp <group> <subcommand> [options]
Examples:
wp plugin list
wp theme activate twentytwentyfour
wp user list
wp core verify-checksums
That structure follows the WP-CLI quick-start and command documentation. (Make WordPress)
Prerequisites before installing WP-CLI
The official install guide says WP-CLI requires PHP 7.2.24 or later. The recommended install method is to download the Phar file, make it executable, and place it somewhere on your PATH, such as /usr/local/bin/wp. (Make WordPress)
For a typical Linux server, you should have:
- PHP available in the shell
curlorwget- permission to write to
/usr/local/bin - shell access to the server where WordPress lives (Make WordPress)
How to install WP-CLI on Linux or macOS
This is the standard official installation flow:
cd /tmp
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info
This is the recommended Phar-based installation approach from the official handbook. (Make WordPress)
If your machine does not have curl, you can use wget instead:
cd /tmp
wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info
The overall process is the same: download, verify, make executable, move into PATH, and confirm with wp --info. (Make WordPress)
How to install WP-CLI when you use XAMPP PHP
If your shell’s default php is not the same PHP binary used by your XAMPP stack, it is safer to run WP-CLI explicitly with your XAMPP PHP path during installation and testing. The official docs support using a custom PHP binary; the wrapper pattern below is a practical way to make that permanent. (Make WordPress)
Example for XAMPP on Linux:
cd /tmp
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
/opt/lampp/bin/php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp.phar
Then create a small wrapper script:
sudo tee /usr/local/bin/wp >/dev/null <<'EOF'
#!/bin/bash
/opt/lampp/bin/php /usr/local/bin/wp.phar "$@"
EOF
sudo chmod +x /usr/local/bin/wp
wp --info
That gives you a plain wp command while still forcing WP-CLI to use the XAMPP PHP binary. This wrapper part is a practical server pattern; the install guide itself covers the Phar approach and custom PHP use. (Make WordPress)
How to verify that WP-CLI is installed correctly
The first command you should run is:
wp --info
That confirms WP-CLI is installed and shows environment details. The install guide uses php wp-cli.phar --info and then wp --info to validate setup. (Make WordPress)
If you are on a WordPress site, also test:
cd /path/to/wordpress
wp core version
wp core is-installed
wp core is-installed is the official way to check whether WordPress is installed for the current path. (WordPress Developer Resources)
If you run WP-CLI as root
On many servers, especially while doing emergency troubleshooting, you may be using root. In that case, WP-CLI often requires --allow-root:
wp plugin list --allow-root
wp theme list --allow-root
You can see supported global parameters, including shared command behavior, in the WP-CLI command docs. (WordPress Developer Resources)
How WP-CLI commands are organized
WP-CLI has top-level command groups, and each group contains subcommands. The official commands page lists the currently available top-level commands and links to their usage pages. (WordPress Developer Resources)
A useful mental model is:
- group = what you want to manage
- subcommand = what you want to do
Examples:
wp plugin list
wp plugin install akismet
wp plugin activate akismet
wp theme list
wp theme activate twentytwentyfour
wp user list
wp user create rajesh rajesh@example.com --role=administrator
This matches the official quick-start pattern and command catalog. (Make WordPress)
The most useful global parameters
Many WP-CLI commands share the same global parameters. The command docs explicitly list global parameters such as --path=<path> and --url=<url>, and the help docs show that wp help can be used for command help. (WordPress Developer Resources)
The most useful ones are:
--path=/path/to/wordpress
--url=https://example.com
--help
Examples:
wp plugin list --path=/var/www/html/site
wp option get siteurl --url=https://example.com
wp help plugin install
These are especially useful for multisite, multiple WordPress installs on one server, or automation scripts. (WordPress Developer Resources)
Full top-level wp command groups
The official commands page is the source of truth, and you should always use wp help on your own server for the live list. The currently documented top-level command groups include the following families: ability, admin, block, cache, cap, cli, comment, config, core, cron, db, dist-archive, embed, eval, eval-file, export, find, help, i18n, import, language, maintenance-mode, media, menu, network, option, package, plugin, post, post-type, profile, rewrite, role, scaffold, search-replace, server, shell, sidebar, site, super-admin, taxonomy, term, theme, transient, user, and widget. (WordPress Developer Resources)
On your own machine, use:
wp help
And for a specific family:
wp plugin --help
wp theme --help
wp db --help
wp user --help
That is the best way to see the exact commands available in your installed WP-CLI environment. (WordPress Developer Resources)
Core WordPress commands you should know first
The core group handles WordPress installation and core maintenance. The official docs include commands such as wp core download, wp core is-installed, and wp core verify-checksums. (WordPress Developer Resources)
Common examples:
wp core download
wp core version
wp core is-installed
wp core verify-checksums
wp core update
These are especially useful when provisioning a new site or verifying whether core files are intact during troubleshooting. (WordPress Developer Resources)
Installing WordPress entirely with WP-CLI
The WP-CLI handbook includes a full flow for installing WordPress: download core, create config, create database, and install WordPress. (Make WordPress)
A typical end-to-end setup looks like this:
wp core download
wp config create \
--dbname=mydb \
--dbuser=myuser \
--dbpass='mypassword' \
--dbhost=localhost
wp db create
wp core install \
--url='https://example.com' \
--title='My Site' \
--admin_user='admin' \
--admin_password='StrongPassword123!' \
--admin_email='admin@example.com'
That flow matches the official WP-CLI installation walkthrough. (Make WordPress)
Config commands
The config group is for wp-config.php creation and updates. WordPress documents wp-config.php as the file containing core configuration details like database connection information, and WP-CLI provides commands to create and manage it. (WordPress Developer Resources)
Useful examples:
wp config create --dbname=mydb --dbuser=myuser --dbpass='secret'
wp config get DB_NAME
wp config set WP_DEBUG true --raw
This is handy when you want reproducible setup instead of editing config files manually. (WordPress Developer Resources)
Database commands
The db group is essential for operations, backups, and integrity checks. The docs include commands like wp db check, which uses your WordPress database credentials from wp-config.php. (WordPress Developer Resources)
Commands you will use a lot:
wp db check
wp db export
wp db import backup.sql
wp db optimize
wp db reset
Be careful with reset on production. For day-to-day work, export, import, and check are the safe ones to learn first. (WordPress Developer Resources)
Plugin commands
The plugin group is one of the most used command families. Official docs cover listing, installing, activating, deactivating, updating, and deleting plugins. (WordPress Developer Resources)
Examples:
wp plugin list
wp plugin install akismet --activate
wp plugin activate rank-math
wp plugin deactivate classic-editor
wp plugin update --all
wp plugin delete hello
This is usually much faster than doing the same actions through wp-admin, especially during troubleshooting. (WordPress Developer Resources)
Theme commands
The theme group gives you the same sort of control for themes. (WordPress Developer Resources)
Examples:
wp theme list
wp theme install twentytwentyfour --activate
wp theme activate twentytwentythree
wp theme update --all
wp theme delete old-theme
This is particularly useful when a site is broken and you need to switch to a default theme fast. (WordPress Developer Resources)
User commands
The user group lets you list users and create new ones from the command line. The official wp user list and wp user create docs cover the most common use cases. (WordPress Developer Resources)
Examples:
wp user list
wp user create rajesh rajesh@example.com --role=administrator
wp user update rajesh --user_pass='NewStrongPassword!'
This is useful when you lose admin access or need to bootstrap accounts during setup. (WordPress Developer Resources)
Post, media, taxonomy, term, and menu commands
WP-CLI also includes groups for content operations: posts, media, taxonomies, terms, menus, and more. The official command catalog lists these families, and the post docs include helpful generators such as wp post generate for creating test data. (WordPress Developer Resources)
Examples:
wp post list
wp post create --post_title="My Test Post" --post_status=publish
wp post generate --count=20
wp media import /path/to/image.jpg --title="Featured Image"
wp term list category
wp menu list
These are handy in development, staging, migrations, and content-heavy maintenance. (WordPress Developer Resources)
Option, transient, and cache commands
The option family is for reading and updating settings stored in the database. The WP-CLI docs describe it as retrieving and setting site options, including plugin and WordPress settings. The WordPress Options API docs explain that these values are stored in the wp_options table. (WordPress Developer Resources)
Examples:
wp option get siteurl
wp option get home
wp option update blogname "My WordPress Site"
wp option delete some_plugin_setting
You will also find transient and cache groups useful when clearing or inspecting temporary data. (WordPress Developer Resources)
Search-replace commands
The search-replace group is a lifesaver during migrations and domain changes. The command docs explicitly support shared global parameters such as --path and --url, which makes it useful in multi-site or multi-install environments. (WordPress Developer Resources)
Typical example:
wp search-replace 'https://old.example.com' 'https://new.example.com'
Use this carefully on production, but it is one of the most important WP-CLI commands to learn. (WordPress Developer Resources)
Language, import/export, cron, rewrite, and maintenance commands
WP-CLI also includes operational commands for language packs, import/export workflows, cron handling, rewrite flushing, and maintenance mode. These groups are all part of the official command catalog. (WordPress Developer Resources)
Examples:
wp language core list
wp export
wp import backup.xml --authors=create
wp cron event list
wp rewrite flush
wp maintenance-mode activate
wp maintenance-mode deactivate
These commands are especially useful when supporting production WordPress sites at scale. (WordPress Developer Resources)
Helpful cli, help, shell, and package commands
There are also WP-CLI commands for introspection and extending WP-CLI itself. The wp cli docs cover information and update-related actions, wp help is the built-in help system, and the package group helps manage extra WP-CLI packages. (WordPress Developer Resources)
Examples:
wp cli info
wp cli update
wp help
wp help plugin install
wp package list
These are the commands you use when learning, debugging, or extending your CLI environment. (WordPress Developer Resources)
A practical starter command set for daily WordPress work
If you want a compact set of commands to memorize first, start with these:
wp --info
wp help
wp core version
wp core verify-checksums
wp plugin list
wp plugin install akismet --activate
wp plugin deactivate some-plugin
wp theme list
wp theme activate twentytwentyfour
wp user list
wp user create admin2 admin2@example.com --role=administrator
wp option get siteurl
wp option update blogname "New Site Name"
wp db export
wp search-replace 'old-url' 'new-url'
These commands cover most everyday admin, recovery, and maintenance workflows. They all come straight from the documented WP-CLI command families. (WordPress Developer Resources)
The safest way to learn all WP-CLI commands
The official commands page is the master directory, but the best real-world habit is to use wp help directly on your own server. That shows the commands actually available in your current WP-CLI install, including any extra packages you may have added. (WordPress Developer Resources)
Use these constantly:
wp help
wp plugin --help
wp theme --help
wp db --help
wp user --help
wp help search-replace
That is the easiest way to move from beginner to advanced usage without trying to memorize everything at once. (WordPress Developer Resources)
A few practical safety tips
First, always cd into the correct WordPress root before running commands, or pass --path=/path/to/site. The global parameter docs explicitly document --path. (WordPress Developer Resources)
Second, be extra careful with destructive commands such as wp db reset, wp plugin delete, wp theme delete, and broad wp search-replace runs. WP-CLI is powerful precisely because it changes things fast. That is a strength, but it also means production safety matters. (WordPress Developer Resources)
Third, on servers where you have multiple WordPress installs or multisite, prefer explicit --path and --url so you know exactly which site you are targeting. The docs note that --url is how the target site is specified in multisite. (WordPress Developer Resources)
Final thoughts
WP-CLI is one of the most valuable tools for anyone who manages WordPress seriously. It is faster than clicking through wp-admin, easier to automate, and incredibly useful for setup, recovery, upgrades, user management, plugin work, and troubleshooting. The official documentation is excellent, and once you understand the command-group pattern, the rest becomes much easier. (Make WordPress)
If you want the best next step after reading this tutorial, install WP-CLI, run wp --info, then open wp help and start with the core, plugin, theme, user, db, and option groups first. Those few command families will already cover a large share of real WordPress work. (Make WordPress)