Back to blog

WP-CLI: Mastering WordPress from the command line

5/23/2025 · 1 min · WordPress

Share

WP-CLI is the official command-line tool for WordPress management. It lets you automate tasks such as creating users, updating plugins, and changing site settings directly on your server.

Basic installation requirements

Before starting, make sure you have:

1. Standard installation (with root/sudo)

Recommended method to run wpcli globally from anywhere in terminal.

Step 1: download WP-CLI

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

Step 2: make it executable

chmod +x wp-cli.phar

Step 3: move to global command path

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

Verification

wpcli --info

If you get WP-CLI, PHP, and OS details, installation is successful.

2. Local installation (without root/sudo)

For jailed shell environments, install inside your user path.

Step 1: create local binary directory

mkdir ubin

Step 2: download WP-CLI

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

Step 3: make it executable

chmod +x wp-cli.phar

Step 4: move to local directory

mv wp-cli.phar ubin/wpcli

How to run it

ubin/wpcli
Warning: even from a subdirectory, wpcli will try to locate wp-config.php to connect to your WordPress installation.

Essential WP-CLI commands

CategoryTaskExample
PluginsList pluginswpcli plugin list
PluginsActivate pluginwpcli plugin activate [slug]
PluginsInstall pluginwpcli plugin install [slug]
UsersList userswpcli user list
UsersCreate userwpcli user create NAME EMAIL --role=ROLE --user_pass=PASSWORD
UsersDelete userwpcli user delete ID
DatabaseExport backupwpcli db export backup.sql
DatabaseImport backupwpcli db import backup.sql
DatabaseOptimize/Repairwpcli db optimize / wpcli db repair
UpdatesUpdate corewpcli core update
UpdatesUpdate all pluginswpcli plugin update --all
UpdatesUpdate all themeswpcli theme update --all
ConfigurationGenerate wp-config.phpwpcli core config --dbname=DB --dbuser=USER
ConfigurationInstall WordPresswpcli core install --url=DOMAIN --title=TITLE

The biggest WP-CLI advantage is operational speed plus easy automation for maintenance workflows.

CC BY-NC

This post is licensed under CC BY-NC.

Comments

Join the discussion below.