WP-CLI is a command-line tool for managing WordPress installations. Instead of clicking through the admin dashboard, you type commands in your terminal. It’s faster, scriptable, and essential for managing WordPress on a VPS.

Is WP-CLI Available?

WP-CLI comes pre-installed on most GoZen Host shared hosting and VPS servers:

  • Shared hosting (cPanel): Available via cPanel Terminal or SSH
  • VPS: Available via SSH
  • Enhance: Available via SSH to your server

Test it:

  wp --version
  

If it’s not installed on your VPS:

  curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
  

Basic Usage

Always run WP-CLI from your WordPress installation directory:

  cd /home/username/public_html
# or on a VPS:
cd /var/www/yourdomain.com
  

Essential Commands

Core Management

  # Check WordPress version
wp core version

# Update WordPress core
wp core update

# Update the database after a core update
wp core update-db

# Download WordPress (fresh install)
wp core download

# Install WordPress
wp core install --url="yourdomain.com" --title="My Site" --admin_user="admin" --admin_password="strongpassword" --admin_email="you@email.com"
  

Plugin Management

  # List all plugins
wp plugin list

# Install a plugin
wp plugin install litespeed-cache --activate

# Update a specific plugin
wp plugin update contact-form-7

# Update all plugins
wp plugin update --all

# Deactivate a plugin
wp plugin deactivate wordfence

# Delete a plugin
wp plugin delete hello-dolly

# Search for plugins
wp plugin search "seo" --per-page=5
  

Theme Management

  # List themes
wp theme list

# Install and activate a theme
wp theme install flavor --activate

# Update all themes
wp theme update --all
  

User Management

  # List users
wp user list

# Create a user
wp user create newadmin admin@yourdomain.com --role=administrator --user_pass="strongpassword"

# Reset a password
wp user update 1 --user_pass="newpassword"

# Delete a user (reassign their posts to user ID 1)
wp user delete 5 --reassign=1
  

Database Operations

  # Optimize database tables
wp db optimize

# Export the database
wp db export backup.sql

# Import a database
wp db import backup.sql

# Run a SQL query
wp db query "SELECT option_value FROM wp_options WHERE option_name = 'siteurl'"

# Search and replace (useful for migrations)
wp search-replace 'http://oldsite.com' 'https://newsite.com' --dry-run
wp search-replace 'http://oldsite.com' 'https://newsite.com'
  

Content Management

  # Delete all spam comments
wp comment delete $(wp comment list --status=spam --format=ids)

# Delete all post revisions
wp post delete $(wp post list --post_type=revision --format=ids)

# Generate test posts (for development)
wp post generate --count=10

# Delete transients
wp transient delete --all
  

Options and Settings

  # Get the site URL
wp option get siteurl

# Update the site URL
wp option update siteurl "https://yourdomain.com"
wp option update home "https://yourdomain.com"

# Get all autoloaded options (performance check)
wp db query "SELECT SUM(LENGTH(option_value)) FROM wp_options WHERE autoload = 'yes';"
  

Maintenance

  # Clear the object cache
wp cache flush

# Regenerate thumbnails
wp media regenerate --yes

# Run cron events
wp cron event run --due-now

# Check site health
wp doctor check --all
  

Practical Recipes

Quick WordPress Install

  cd /var/www/yourdomain.com
wp core download
wp config create --dbname=wp_database --dbuser=wp_user --dbpass=password
wp core install --url="yourdomain.com" --title="My Site" --admin_user=admin --admin_password=strongpass --admin_email=me@email.com
wp plugin install litespeed-cache wordfence --activate
wp rewrite structure '/%postname%/'
  

Fix a Hacked Site

  # Reinstall core files (won't touch your content)
wp core download --force

# Check for unknown files
wp core verify-checksums

# Reinstall all plugins from WordPress.org
wp plugin install $(wp plugin list --field=name) --force

# Change all admin passwords
wp user update $(wp user list --role=administrator --format=ids) --user_pass="newstrongpassword"
  

Speed Audit

  # Check autoloaded data size (should be under 800KB)
wp db query "SELECT SUM(LENGTH(option_value)) as total_bytes FROM wp_options WHERE autoload = 'yes';"

# Find the largest autoloaded options
wp db query "SELECT option_name, LENGTH(option_value) as size FROM wp_options WHERE autoload = 'yes' ORDER BY size DESC LIMIT 20;"

# Delete transients
wp transient delete --all

# Clean revisions
wp post delete $(wp post list --post_type=revision --format=ids) 2>/dev/null
  

Last updated 19 Apr 2026, 23:46 +0300. history

Was this page helpful?