WP-CLI for WordPress Developers — Automate Deploy and Maintenance from Terminal
> cd .. / HUB_EDITORIALE
Sviluppo di siti web

WP-CLI for WordPress Developers — Automate Deploy and Maintenance from Terminal

[2026-07-12] Author: Ing. Calogero Bono
> share
Zenithby Meteora Web The operating system for your business. Social, clients, bookings and invoices in one platform. Gyms, barbers, professionals. Discover Zenith Free demo · no card

If you manage multiple WordPress sites, clicking "Update" on dozens of plugins one by one is a waste of time. What if you could do it all from the terminal in seconds, with a single command? WP-CLI turns WordPress management into command-line operations: deploy, updates, backups, migrations. We at Meteora Web use it daily for our clients' projects. We come from accounting and programming: every saved minute is a minute we can invest in what generates revenue. This operational guide covers installation, essential commands, and how to integrate WP-CLI into automation workflows for your business.

How to install WP-CLI on a Linux server?

WP-CLI is a PHP executable distributed as a PHAR file. Installing it on a Linux server (or local dev environment) is straightforward.

Installation with wget or curl

# Download official PHAR
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

# Verify it works
php wp-cli.phar --info

# Make executable and move to /usr/local/bin
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

# Test
wp --version

Common mistake: forgetting to make the file executable. Without `chmod +x`, the `wp` command will give "Permission denied".

Sponsored Protocol

Check prerequisites

WP-CLI requires PHP 5.6+ (recommended 7.4+) and the `json`, `phar`, `curl`, `mysql` extensions. Check with:

php -m | grep -E 'json|phar|curl|mysql'

If missing, install via your OS package manager (e.g. `sudo apt install php-json` on Debian/Ubuntu).

Which WP-CLI commands to use for automatic deployment?

Deploying a WordPress site with WP-CLI can be fully automated. Here are the commands we use daily in CI/CD pipelines.

Update core, plugins and themes

# Update WordPress core
wp core update

# Update all plugins
wp plugin update --all

# Update all themes
wp theme update --all

Pro tip: always backup the database before updates. Do it in one go:

wp db export backup-$(date +%Y%m%d).sql
wp core update
wp plugin update --all
wp theme update --all

Search and replace in the database

When moving a site between environments (local → staging → production), you need to update URLs. With WP-CLI it's instant:

wp search-replace 'http://localhost' 'https://yourdomain.com' --all-tables

Important: always use the `--precise` flag if you have serialized data (typical in WordPress) to avoid corruption. We prefer:

Sponsored Protocol

wp search-replace 'http://localhost' 'https://yourdomain.com' --all-tables --precise

Export and import database

# Export
wp db export mydb.sql

# Import (caution: overwrites current database)
wp db import mydb.sql

To duplicate a site, combine export/import with URL replacement:

wp db export staging.sql
wp db import staging.sql
wp search-replace --all-tables --precise 'old.com' 'new.com'

How to manage plugin and core updates with WP-CLI?

Regular updates are crucial for security. With WP-CLI you can schedule them via cron.

Check available updates

# List updates
wp core check-update
wp plugin list --update=available
wp theme list --update=available

Selective updating

# Update a specific plugin
wp plugin update woocommerce

# Update a specific theme
wp theme update twentytwentyfour

Automate with cron (Unix)

Add a job to crontab:

# Every Monday at 3:00
0 3 * * 1 cd /path/to/wp && wp core update && wp plugin update --all && wp theme update --all

Note: ensure the cron user has write permissions on the WordPress directory. We recommend running the command as the site user (not root).

Sponsored Protocol

How to export and import the database with WP-CLI for migrations?

Migrations between servers or environments are critical operations. WP-CLI makes them safe and fast.

Export with compression

wp db export - | gzip > backup-$(date +%Y%m%d).sql.gz

To import a compressed file:

gunzip < backup.sql.gz | wp db import -

Full remote migration

On the target server, use WP-CLI with SSH:

ssh user@old-server 'cd /path/wp && wp db export -' | wp db import -

This avoids saving temporary files. Convenient but watch bandwidth.

How to create Bash scripts for automation with WP-CLI?

True automation comes from combining WP-CLI with Bash. Here's a script we wrote for a client with 30 WooCommerce sites: updates all, backs up, and sends a notification.

#!/bin/bash
SITES=("/var/www/site1" "/var/www/site2" "/var/www/site3")
for SITE in "${SITES[@]}"; do
    echo "Working on $SITE"
    cd "$SITE"
    wp db export "backup-$(date +%Y%m%d).sql"
    wp core update
    wp plugin update --all
    wp theme update --all
    echo "Done $SITE"
done

Production script checklist:

Sponsored Protocol

  • Verify directory exists
  • Use `set -e` for error handling
  • Log output to a file
  • Notify via email or Slack on failure

We integrated a similar script into a continuous deployment system: every Git push triggers automatic updates on staging and, after testing, on production.

What to do next

WP-CLI is not just a developer tool — it's an efficiency multiplier for anyone managing WordPress professionally. Three concrete actions to take today:

  1. Install WP-CLI on your development or staging server using the commands above.
  2. Create an automatic backup with a cron job that runs `wp db export` daily.
  3. Write a Bash script that updates plugins and themes on a test site to get comfortable.

Remember: a website is not a showcase to admire — it's a tool that must sell. The more time you save on maintenance, the more time you invest in growing it. For deeper insights, check our WordPress Advanced Development Pillar Guide.

Useful link: Official WP-CLI Documentation

> share
Ing. Calogero Bono

> AUTHOR_EXTRACTED

Ing. Calogero Bono

Ingegnere informatico, fondatore di Meteora Web e Zenith OS. System administrator e progettista di piattaforme, app e CMS proprietari, con esperienza in sviluppo full-stack, marketing digitale ed ecosistema Google.
[ Read Full Dossier ]

> METEORA_WEB // DIGITAL AGENCY

We build the digital presence your business deserves.

Websites, social media, online advertising, e-commerce and high-performance hosting, engineered with method by computer engineers in Sciacca, for all of Italy.

> MW_JOURNAL

> READ_ALL()