WP-CLI: The Terminal Way to WordPress — Part 1

Published: (May 3, 2026 at 12:25 PM EDT)
4 min read
Source: Dev.to

Source: Dev.to

Why WP-CLI?

Stop clicking through wp‑admin for every small task. WP‑CLI is the official command‑line interface for WordPress, letting you manage sites faster—from your terminal.
Typical dashboard actions (updating plugins, flushing cache, resetting passwords, running a search‑replace) can require 30+ clicks. With WP‑CLI it’s often a single line.

Problems It Solves

  • Bulk operations – update all plugins or themes in one command.
  • Database search‑replace – migrate sites without breaking serialized data.
  • Locked out of wp‑admin? – reset passwords or create admin users directly from the CLI.
  • Repetitive setup tasks – automate the same steps for every new project.
  • Cron & scheduled tasks – trigger wp‑cron reliably from server crontabs.

Is It Good or Bad?

Honest answer: Excellent for developers; a non‑issue for anyone who never opens a terminal.

✅ Good For

  • Developer workflows
  • Managing multiple sites
  • Automating repetitive tasks
  • Faster deployments

⚠️ Watch Out For

  • No undo on destructive DB commands
  • Wrong path can affect the wrong site
  • Requires SSH/terminal access
  • Some shared hosts may restrict it

Golden rule: Always test destructive commands on a staging environment first. Power cuts both ways.

Setup & Installation

Step‑by‑step (Linux/macOS)

# Step 1 — Download the Phar file
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

# Step 2 — Make it executable and move it globally
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

# Step 3 — Verify the installation
wp --info

You should see your OS, PHP version, and WP‑CLI version. If you do — you’re good to go.

Alternative installations

  • Composer: composer global require wp-cli/wp-cli-bundle
  • WSL (recommended) for Windows users.
  • LocalWP, DevKinsta, DDEV: WP‑CLI is already bundled — no setup needed.

Tip: Run all commands from your WordPress root directory.

Must‑Know Commands

CommandWhat It Does
wp core installInstall WordPress in one shot
wp plugin install --activateInstall and activate a plugin from wordpress.org
wp plugin update --allUpdate every plugin at once
wp theme activate <theme>Switch the active theme instantly
wp user create <user> --role=<role> --user_pass=<pass>Create a user with role and password
wp search-replace 'old' 'new'Safe database search‑replace (handles serialized data)
wp db export <file> / wp db import <file>Backup or restore your database
wp cache flushClear the object cache
wp option get <name> / wp option update <name> <value>Read or change wp_options values
wp cron event run <event>Manually trigger a WP‑Cron event

Full command reference →

Real‑World Use Case: Moving a Site

After transferring files and importing the DB, run:

wp search-replace 'localhost' 'staging.example.com' --all-tables

Serialized data is handled safely—no broken arrays, no manual SQL editing. What used to take 20 minutes now takes seconds.

Your First Custom Script

Create a shell script to set up a fresh WordPress install with your go‑to plugins.

#!/bin/bash
# setup.sh — run after: wp core download && wp config create

# Install WordPress
wp core install \
  --url=localhost \
  --title="My Site" \
  --admin_user=admin \
  --admin_email=you@dev.com

# Install & activate standard plugins
wp plugin install wordfence woocommerce yoast-seo --activate

# Set a clean permalink structure
wp rewrite structure '/%postname%/' --hard

echo "✅ Setup complete!"

Save as setup.sh, make it executable (chmod +x setup.sh), and run it after every fresh install. Consistent environment, zero effort.

What’s Next

In Part 2 we’ll dive deeper:

  • Writing advanced custom PHP commands with WP_CLI::add_command()
  • Using WP‑CLI in CI/CD pipelines
  • Managing remote WordPress sites
  • --dry-run patterns so you never break production

Found this helpful? Drop a ❤️ and stay tuned for Part 2!

0 views
Back to Blog

Related posts

Read more »

Code Is a Commodity. Judgment Is Not.

The Shift in Value AI can write code—good code, clean code, fast code. That doesn’t make development trivial; it shifts where the true value lives. When code w...