WP-CLI Guide for Talent Acquisition Teams and Admins
A Beginner’s Guide to WP-CLI: Useful Commands with Examples
- Quickly manage WordPress installations directly from the command line.
- Learn essential commands along with their practical applications.
- Explore automation and staging environments for safe deployments.
Table of Contents
- What is WP-CLI and why use it?
- Before you start: prerequisites and safe setup
- Installing and verifying WP-CLI
- Navigating to the WordPress root
- Essential WP-CLI commands with examples
- WP-CLI for multisite and large installations
- Automation, deployment, and CI/CD with WP-CLI
- Security and safety best practices
- Troubleshooting common WP-CLI errors
- WP-CLI packages and extending WP-CLI
- Real-world use cases: How teams use WP-CLI
- Practical checklist: Start using WP-CLI today
- Final tips and recommended workflows
What is WP-CLI and why use it?
WP-CLI (WordPress Command Line Interface) is a command-line tool that lets you manage WordPress installations without using the admin dashboard. You can do almost anything — install WordPress, update core, install and activate plugins and themes, manage users, run database search-and-replace, export/import content, scaffold plugins and themes, and even open an interactive PHP shell.
Why it matters:
- Speed: One command replaces many clicks.
- Automation: Integrate WordPress tasks into scripts, CI/CD pipelines, and cron jobs.
- Scale: Manage multiple sites consistently and quickly.
- Precision: Run repeatable operations with programmable flags and options.
If you host your sites on a VPS or dedicated server, WP-CLI becomes essential. Consider testing WP-CLI workflows on a development server or using a managed WordPress environment. For seamless SSH and WP-CLI access, explore Dasabo’s VPS Hosting and WordPress Hosting.
Before you start: prerequisites and safe setup
To use WP-CLI effectively you need:
- SSH access to the server (or local terminal if running locally).
- A PHP CLI environment and the WordPress files accessible from the command line.
- Proper file permissions so wp can read wp-config.php and access the database.
Basic setup checklist:
- SSH into your server (or open your terminal locally).
- Change directory to your WordPress root:
cd /path/to/your/wordpress - Verify WP-CLI:
wp --info - Make sure the
wpcommand is executable and on your PATH.
If you’re on a managed WordPress plan and need SSH or WP-CLI enabled, Dasabo’s WordPress Hosting gives a developer-friendly environment with WP-CLI support. If you prefer full server control, Dasabo’s VPS Hosting or dedicated server solutions let you tailor PHP, Composer, and WP-CLI exactly how you want.
Installing and verifying WP-CLI
Typical quick install (example for servers with PHP and curl/wget available):
1. Download the phar: 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 a directory on PATH and rename: sudo mv wp-cli.phar /usr/local/bin/wp 4. Verify: wp --info
Common verification outcomes:
- If
wp --infoprints version and environment info, you’re set. - If you get “command not found”, the
wpexecutable isn’t on PATH or not installed. - If you see “Could not open input file”, you likely ran a command from outside the WordPress root; cd into the correct directory.
If you prefer a managed route, using Dasabo’s VPS gives you full root or sudo access to install WP-CLI exactly as needed.
Navigating to the WordPress root
Most WP-CLI commands must be run from the WordPress installation root (where wp-config.php lives). Example:
cd /var/www/example.com/public_html wp core version
If you manage multiple installs, use absolute paths:
wp --path=/var/www/site1/public_html core version
Essential WP-CLI commands with examples
Here are the commands every beginner should know — with examples you can copy and adapt.
Core commands
- Check WordPress version:
wp core version
- Update core (to latest minor or major):
wp core update
- Install a fresh WordPress site:
wp core install --url=example.com --title="My Site" --admin_user=admin --admin_password='StrongPass123' --admin_email=admin@example.com
Plugin management
- List plugins:
wp plugin list
- Install and activate a plugin:
wp plugin install jetpack --activate
- Update all plugins:
wp plugin update --all
- Deactivate and uninstall:
wp plugin deactivate hello wp plugin delete hello
WP-CLI lets you batch-manage plugins quickly — handy for updating dozens of client sites. If you run mission-critical WordPress, using a reliable hosting platform improves update stability. Our WordPress Hosting plan includes optimizations for plugin performance and compatibility.
Theme management
- List themes:
wp theme list
- Activate a theme:
wp theme activate twentytwentythree
- Install a theme:
wp theme install astra --activate
User management
- List users:
wp user list
- Create a user:
wp user create bob bob@example.com --role=author --user_pass=RandomP@ssw0rd
- Update a user password:
wp user update bob --user_pass=NewStrongPassword
- Set a user role:
wp user set-role bob editor
Post and content management
- Create a post:
wp post create --post_type=post --post_title="Hello from WP-CLI" --post_status=publish --post_author=1
- Update a post’s content:
wp post update 123 --post_content="Updated content via WP-CLI"
- List posts:
wp post list --post_type=post --format=table
Media and images
- Import a media file as attachment:
wp media import /tmp/photo.jpg --post_id=123 --title="Event Photo"
- Regenerate thumbnails (for a specific attachment or all):
wp media regenerate --yes
Database tasks
- Export database:
wp db export # creates a SQL file in the current directory
- Import:
wp db import dump.sql
- Run a search-and-replace (always backup first!):
wp search-replace 'http://staging.example.com' 'https://example.com' --all-tables --dry-run # remove --dry-run to execute
Config and options
- Generate a wp-config.php:
wp config create --dbname=wp_db --dbuser=wp_user --dbpass='dbpass' --dbhost=localhost
- Get or set an option:
wp option get home wp option update blogname "New Blog Name"
Cron, cache, and cron events
- Run scheduled events:
wp cron event run --due-now
- Clear object/cache (depends on cache plugin support):
wp cache flush
Advanced developer tools
- Scaffold a plugin:
wp scaffold plugin my-plugin --author="Your Name" --activate
- Start an interactive PHP shell:
wp shell # now you can run PHP code directly
- Create users, posts, and test content for development:
wp post generate --count=50 wp user generate --count=10
WP-CLI for multisite and large installations
WP-CLI has robust multisite commands. Examples:
- List all sites:
wp site list
- Update all sites in a network:
wp --url=example.com plugin update --all --network
- Run search-replace across the whole network:
wp search-replace 'http://old' 'https://new' --network --all-tables --dry-run
Large installations benefit most from scripting and scheduled maintenance using WP-CLI to avoid overloading the admin UI.
If you’re managing many sites or large traffic, consider a VPS or dedicated server to handle CLI operations reliably. Dasabo’s server solutions provide the performance and control you need for scalable WordPress deployments.
Automation, deployment, and CI/CD with WP-CLI
WP-CLI integrates well into deployment pipelines:
- Use scripts for blue-green deployments (export DB, run search-replace, import).
- Run plugin and core updates as part of a build step.
- Use Composer and WP-CLI together for reproducible environments.
- Add WP-CLI commands to your CI (GitHub Actions, GitLab CI, etc.) for testing site changes.
Example deployment hook:
# Pull latest code git pull origin main # Install/update dependencies composer install --no-dev # Run DB migrations or search-replace for environment differences wp db export db-before.sql wp search-replace 'http://staging.example.com' 'https://example.com' --all-tables --skip-columns=guid # Clear caches and run cron wp cache flush wp cron event run --due-now
Using a solid hosting provider with SSH and resource scaling makes this reliable — explore Dasabo’s VPS Hosting for build-friendly environments.
Security and safety best practices
WP-CLI is powerful, and like any powerful tool it must be used carefully:
- Always backup before destructive commands (
wp db export,wp search-replace, plugin/theme deletions). - Use SSH key authentication instead of password logins.
- Limit SSH access to trusted IPs where possible.
- Run commands with the least privilege necessary — avoid running everything as root.
- Use
wp-cli.ymlto define default flags (e.g., skip confirmations) in controlled environments. - Protect your
wp-config.phpand database credentials; WP-CLI reads them to function. - Rotate and store DB and admin passwords securely when using scripted installs.
If you want a secure, managed environment with predictable backups and high-availability, Dasabo’s Web Hosting and WordPress Hosting include protective measures and support options to keep your site safe and performant.
Troubleshooting common WP-CLI errors
- “command not found”: WP-CLI is not installed or not on PATH. Ensure
wpis executable and in/usr/local/binor similar. - “Could not open input file”: You’re not in the WordPress root or the provided
--pathis incorrect. cd to the right directory. - Permissions errors: Ensure the user running WP-CLI has read/write permission to WordPress files and the database. Avoid running everything as root.
- Database connection errors: Check
wp-config.phpDB credentials and that MySQL/MariaDB is running. - Memory/timeouts: For large operations, increase PHP CLI memory_limit or split large operations into smaller batches.
- Plugin/theme conflicts: If a plugin blocks admin but WP-CLI won’t run a command, try
wp plugin deactivate --allthen reactivate selectively.
Always run potentially destructive commands with caution, and use --dry-run when available for search-and-replace operations.
WP-CLI packages and extending WP-CLI
WP-CLI supports packages that add new commands. Install packages with:
wp package install git+https://github.com/some/package.git
Popular categories:
- Migration helpers
- Deployment helpers
- Dev utilities (generate test data, scaffolding)
- Integration with cloud services
Packages can streamline repetitive tasks and integrate WP-CLI with your broader toolchain.
Real-world use cases: How teams use WP-CLI
- Agencies: Bulk plugin/theme updates across client installs and scripted deploys.
- Developers: Scaffold plugins/themes and run unit tests via WP-CLI or WP-CLI PHPUnit integration.
- Site owners: Quick password resets and emergency plugin deactivations if the admin area is broken.
- DevOps: Automate database migrations, search-replace on deployment, and manage cron events.
For teams that want predictable environments and near-instant operations, combining WP-CLI with reliable hosting and domain management is critical. Use Dasabo’s domain registration to centralize your domains and our hosting to centralize your WordPress operations.
Practical checklist: Start using WP-CLI today
- Ensure SSH access to your server or local development environment.
- Install WP-CLI or confirm it’s installed:
wp --info - cd into your WordPress root and run
wp core versionto verify. - Backup:
wp db exportbefore any big change. - Practice basic commands on a staging copy (
wp plugin list,wp theme list,wp user list). - Write small scripts for repeated tasks and test them in staging.
- Integrate into your deployment pipeline once comfortable.
If you need a reliable environment to test and run WP-CLI at scale, Dasabo’s hosting and server plans make it simple to get SSH access and a performant stack.
Final tips and recommended workflows
- Use a staging environment for updates and testing before pushing to production.
- Combine Composer for code and WP-CLI for database/content tasks for reproducible deployments.
- Create reusable shell scripts and document them for your team.
- Schedule routine maintenance (backups, updates) as automated tasks using cron and WP-CLI.
- Audit and limit who can SSH into production systems and log WP-CLI actions for accountability.
WP-CLI can be a game-changer once incorporated into your operations. Whether you’re a developer optimizing deployments, an agency managing dozens of client sites, or a site owner who wants to do advanced maintenance without the admin UI, WP-CLI speeds up work and reduces human error.
For reliable environments, backups, and SSH access to run WP-CLI efficiently, check out Dasabo’s Web Hosting, WordPress Hosting, and Servers.