// DevOps

WP-CLI: A Comprehensive Guide to Managing WordPress from the Command Line

Published on 2025-09-19


Introduction

WP-CLI is the official command-line tool for WordPress, allowing you to manage your sites without logging into the admin panel. With WP-CLI, you can install plugins, update WordPress core, manage users, handle database tasks, and even run advanced automation workflows.

In this guide, we’ll explore what WP-CLI is, how to install it, and provide practical examples of its most useful commands.


What is WP-CLI?

WP-CLI (WordPress Command Line Interface) is a PHP-based tool that enables direct interaction with WordPress through the terminal. It covers almost all admin tasks and sometimes goes beyond the WordPress dashboard:

  • Installing and updating WordPress core, plugins, and themes
  • Managing users, posts, and the database
  • Running bulk operations across multiple sites
  • Remote management via SSH
  • Automating workflows with scripts

Benefits of WP-CLI

  • Efficiency: Tasks are completed much faster compared to the admin panel.
  • Bulk operations: Update all plugins or clear caches across multiple sites with one command.
  • Automation: Use WP-CLI inside Bash or PHP scripts for deployments, backups, or migrations.
  • Remote access: Manage WordPress via SSH without a browser.
  • Extended functionality: Commands not available in the dashboard (e.g., clearing transients).

Installing WP-CLI

Requirements

  • UNIX-like environment (Linux, macOS, FreeBSD).
  • PHP 5.6+
  • WordPress 3.7+

Installation steps

  1. Download the Phar file:

    bash
    curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
  2. Make it executable:

    bash
    chmod +x wp-cli.phar
  3. Move it to your $PATH:

    bash
    sudo mv wp-cli.phar /usr/local/bin/wp
  4. Verify:

    bash
    wp --info

For cPanel (no root access):

bash
alias wp='~/wp-cli.phar'
echo "alias wp='~/wp-cli.phar'" >> ~/.bashrc

👉 WP-CLI can also be installed via Composer, Homebrew, or Docker.


Common WP-CLI Commands

Core management

bash
wp core download --path=wp-site
wp core install --url="http://example.com" --title="My Site" --admin_user="admin" --admin_password="securepassword" --admin_email="admin@example.com"
wp core update
wp core install --skip-content

Plugins

bash
wp plugin install akismet --activate
wp plugin update --all
wp plugin deactivate --all

Themes

bash
wp theme install twentytwentyone --activate
wp theme list

Database

bash
wp db export backup.sql
wp db import backup.sql
wp search-replace 'http://old.com' 'https://new.com' --dry-run

Users

bash
wp user create newuser user@example.com --role=editor --user_pass=securepassword
wp user delete 42 --reassign=1

Content

bash
wp post create --post_type=post --post_title="New Post" --post_status=publish
wp post generate --count=10

Advanced

bash
wp transient delete --all
wp config set WP_DEBUG true --raw
wp eval 'echo get_option("siteurl");'

Advanced Features

Custom commands

Developers can write their own WP-CLI commands. Use:

bash
wp scaffold package

to generate a template for custom commands.

Remote management

bash
wp --ssh=user@host:/path/to/wordpress plugin install akismet --activate

Automation with scripts

bash
#!/bin/bash
for site in /var/www/site1 /var/www/site2; do
  wp --path=$site plugin update --all
done

Troubleshooting

  • WP-CLI version: wp cli version
  • Command help: wp help plugin install
  • Debugging: wp plugin install akismet --debug

Common issues:

  • Permission denied → run as correct user.
  • Path not found → specify --path=/var/www/site.

Conclusion

WP-CLI is a must-have for WordPress developers and administrators. It makes repetitive tasks faster, supports automation, and allows for remote management. By mastering its core commands, you’ll save time and gain better control over your WordPress projects.

📚 Learn more: wp-cli.org

Run wp help to discover available commands.

// Contact

Need help?

Get in touch with me and I'll help solve the problem

Message on Telegram

Отвечаю в течение рабочего дня (03:00–13:00 GMT)

Или оставьте заявку здесь:

Send request
Write and get a quick reply