Use WP-CLI

wp-cli, wp, ssh, command line, search-replace, cron · 0 found this helpful

WP-CLI (the wp command) runs WordPress tasks from a terminal. It is faster than clicking and can fix a site when wp-admin won't load. It's installed at /usr/local/bin/wp. To type commands you need SSH or Terminal, which come with Business and Pro. On Essential you can still run wp from a cron job.

Open a terminal

Use SSH (Connect with SSH) or Account → Hosting → your site → Developer → Open Terminal (Use the browser terminal). Then go to your site's folder:

cd ~/public_html
wp --info

If you see PHP and WordPress versions, it works.

Everyday commands

# Status
wp core version
wp core check-update
wp option get siteurl

# Updates
wp core update
wp plugin update --all
wp theme update --all
wp plugin list

# Turn plugins on and off
wp plugin deactivate --all
wp plugin activate contact-form-7

# Users
wp user list
wp user update sarah --user_pass='Long-New-Passphrase-42'
wp user create editor [email protected] --role=editor

# Cache and rewrite rules
wp cache flush
wp rewrite flush

# Scheduled tasks
wp cron event list
wp cron event run --due-now

Search and replace safely

Always preview first.

# Preview
wp search-replace 'http://example.ca' 'https://example.ca' --dry-run

# Run it, skipping the guid column
wp search-replace 'http://example.ca' 'https://example.ca' --skip-columns=guid

# One table only
wp search-replace 'old' 'new' wp_posts --dry-run

WP-CLI handles serialized data. See Change a WordPress site's URL.

Database

wp db export ~/backups/site-$(date +%F).sql
wp db import ~/backups/site.sql
wp db check
wp db optimize

See Export a database.

Edit wp-config.php

wp config set WP_MEMORY_LIMIT 256M
wp config set WP_DEBUG true --raw
wp config get DB_NAME

Install a fresh site

wp core download --locale=en_CA
wp config create --dbname=example_wp --dbuser=example_wpuser --prompt=dbpass
wp core install --url=https://example.ca --title="North Shore Bakery" \
  --admin_user=sarah [email protected]

Most people should use the WordPress section of their account instead.

Run a real cron instead of WP-Cron

*/10 * * * * cd /home/yourusername/public_html && /usr/local/bin/wp cron event run --due-now >/dev/null 2>&1

Add it as a scheduled task in Developer. See cron jobs, and set define( 'DISABLE_WP_CRON', true ); in wp-config.php.

If something goes wrong

  • "Error: This does not seem to be a WordPress installation": you're not in the site folder.
  • Memory errors: php -d memory_limit=512M $(which wp) plugin update --all.
  • Wrong PHP version: see Pick a PHP version.

Was this helpful?

Still stuck? Ask us and we'll walk you through it.