RU RU

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

Published on September 19, 2025


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

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:

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

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

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

    wp --info
    

For cPanel (no root access):

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

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

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

Themes

wp theme install twentytwentyone --activate
wp theme list

Database

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

Users

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

Content

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

Advanced

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:

wp scaffold package

to generate a template for custom commands.

Remote management

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

Automation with scripts

#!/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.

Need help?

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

Related Posts