WP-CLI, short form for WordPress Command Line Interface, is a powerful tool that allows users to manage their WordPress sites directly from the Command line or terminal, bypassing the need to navigate the WordPress dashboard. It enables developers and site administrators to execute tasks and manage their sites more efficiently and quickly.
Table of Contents
As WordPress sites grow, using WP-CLI helps site administrators automate repetitive tasks, script complex commands, and maintain a higher level of consistency across all aspects of site management.
WP-CLI reduces the time developers spend on routine tasks, by replacing time-consuming, manual processes with fast command-line commands.
For tech-savvy site owners, WP-CLI offers advanced control over WordPress sites, often beyond what the typical WordPress dashboard provides. It’s useful for advanced troubleshooting and bulk site management.
Setting Up WP-CLI on Your System
System Requirements
WP-CLI is a versatile and essential tool for developers and administrators looking to streamline WordPress site management. With WP-CLI, you can perform various tasks such as updating plugins and themes, configuring settings, creating backups, managing databases, and even generating new content with all simple commands.
Before installing WP-CLI, make sure your environment meets the following basic requirements.
Operating System.
- Linux. It is most common and fully supported. (Ubuntu, CentOS, etc)
- macOS. Fully supported and commonly used by developers.
- Windows. Requires additional setup via WSL(Windows Subsystem for Linux) and is not natively supported.
PHP Version
- Minimum: 7.4
- Recommended: 8.0 or higher.
- Since WP-CLI runs on PHP, having an updated PHP version ensures better compatibility and performance.
WordPress Version
- WordPress versions 3.7 and higher. However, using the latest WordPress version is best to avoid compatibility issues.
Database
- WP-CLI requires a MYSQL or MariaDB database connection. You should have the command-line access to the database.
Access
- You need SSH or command-line access to the server where WordPress is installed.
Download Instructions.
Step 1: Download WP-CLI
Open your terminal(or Command prompt for Windows users with WSL).
Run the following command to download WP-CLI.
| curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar |
This command fetches the wp-cli.phar file is a PHP Archive (PHAR) that can be executed directly.
Step 2: Verify the PHAR file.
Check the file for validity to ensure that the download was successful and that the file was not corrupted.
php wp-cli.phar –info
If this command returns information about WP-CLI, the download was successful.
Step 3: Make WP-CLI executable.
Make the file executable by running the following command.
| chmod +x wp-cli.phar |
Step 4: Move WP-CLI to a global location.
To use WP-CLI from any directory, move it to a directory in your system’s path, such as /usr/local/bin/
| sudo mv wp-cli.phar /usr/local/bin/wp |
Now, you can run WP-CLI commands.
Step 5: Test the installation.
Verify the installation by running the following:
| wp –info |
This should display the version of WP-CLI, PHP, and other system information.
Alternative method for Windows users.
For Windows users not using WSL, you can set up WP-CLI using Cygwin or Command Prompt.
We shall use Windows Command Prompt or Git Bash to run WP commands since It offers a Linux-like environment, making some commands easier to execute.
Step 1: Install PHP
- Download PHP.
- Go to the PHP for Windows website.
- Choose the latest stable version e.g. PHP 8.xxx. Download the Thread Safe version as a Zipped file.
- Extract PHP.
- Extract the downloaded file to a folder like C:\php
- Set up the PHP Path.
- Right-click on the Windows button and choose System.
- Click on Advanced Settings > Environment Variables.
- Under System Variables, find the path variable and click Edit.
- Click New and add the path to your PHP folder (C:\php)
- Click OK to save the changes.
- Verify the PHP Installation.
- Open the Command Prompt and type: php -v
- You should see the PHP version information.

Step 2: Download WP-CLI
Download the WP-CLI Phar file.
- Open Git bash
- Run the following command to download the wp-cli.phar file.
| curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar |
Verify the Download
- To check if the download is working, run;
php wp-cli.phar –info

You should see the WP-CLI information and PHP version.
Step 3: Set up WP-CLI as a command.
To use wp globally instead of typing php wp-cli.phar each time;
- Move wp-cli.phar to a Global folder like C:\wp-cli
- Rename wp-cli.phar to wp.phar for simplicity.
- Create a Batch File.
- Open a Code editor and paste the following code;
| @echo off php “C:\wp-cli\wp.phar” %* |
- Save this file as wp.bat in the same folder as C:/wp-cli
- Update the Environment Path.
- Go to Environment Variables again as in Step 1.
- Add the path C:\wp-cli to your Path variable.
- Test WP-CLI
- Open the Command Prompt and type wp –info
- You should see WP-CLI information.

How to use WP CLI?
Once you have installed WP-CLI, it’s time to configure it and familiarize yourself with the basics. Before diving into live site management, it’s highly recommended that you practice using WP-CLI in a staging environment.
InstaWP makes it incredibly easier to spin up a WordPress website for testing, learning, and experimentation without affecting your live site.
Setting Up WP-CLI on InstaWP
InstaWP makes it easy to harness the power of WP-CLI seamlessly and efficiently. By combining InstaWP’s staging capabilities with WP-CLI’s command-line power, you can save time and effort managing bulk WordPress sites.
Save WP-CLI commands
- Access the terminal in InstaWP
- Go to your Account Settings and Click on Commands.

- Save Commands
- Add WP-CLI commands by clicking on the Add Command button.
- Click on Save to save the commands for future use.
- All your WP-CLI saved commands will appear on the left-hand side of the terminal.

- Run your desired WP-CLI Commands.
- Launch your WP instance and access the terminal interface provided in the dashboard.
- Select the WP-CLI command from the drop-down.
- Click on Run Command to execute it.

- Reuse Saved Commands.
- When launching a new instance, you can apply these saved commands automatically, ensuring your site is instantly configured with your preferred setup.
Step 1: Create a Staging Site
- Create a Staging site on InstaWP.
- Go to your Staging site and click the 3 dots at the right(More Actions).
- Then click on Commands.

- InstaWP will open a terminal where you can run wp commands.

Step 2. Basic WP-CLI Configuration
- Check the WP-CLI version.
- To ensure WP-CLI is installed correctly, check the version using this command.
wp –version
- Check Site status.
- Verify your WordPress setup with;
wp core status
- This command provides information about your WordPress version, Database connection, and Configuration.
- Create a Test Post.
- You can create a new post to test the WP-CLI setup.
| wp post create –post_title=”Hello World from WP-CLI” –post_status=publish |
Visit your site to see the new post, confirming your setup works.
Step 3. Use Initial Commands.
- List all Plugins.
wp plugin list
- Update WordPress Core.
| wp core update |
- Flush Cache(if using a cache plugin)
| wp cache flush |
- Access help or any command.
| wp help |
Running Saved Commands on Multiple Sites
Managing multiple websites can be time-consuming, but with InstaWP and WP-CLI, you can execute saved commands across several instances simultaneously.
How to Run Saved Commands on Multiple InstaWP Sites
- Setup Site Templates.
- Create Site templates in InstaWP that include your saved WP-CLI commands.
- Clone the templates across instances.
- When creating new sites, choose the template with the pre-saved WP-CLI commands.
- InstaWP will apply these commands during the site setup.
- Batch Execution via InstaWP API.
- InstaWP’s API can trigger saved WP-CLI commands across several instances programmatically.
Example API Call.
| { “action”: “run_wp_cli”, “commands”: [“wp plugin update –all”, “wp cache flush”], “instances”: [“site1”, “site2”, “site3”] } |
- This ensures you maintain updates, configurations, and other tasks simultaneously.
WP-CLI Basics: Must-Know Commands
WP-CLI provides a wide range of commands to manage various aspects of your website. Below are some essential categories of commands that every user should know.
Updating and Managing Core Files
WP-CLI makes it easy to update your core files or check their status.
- Check Core Version.
| wp core version |
Displays the current version of WordPress installed on your website.
- Update WordPress Core.
wp core update
Updates WordPress Core to the latest version.
- Verify Core integrity.
| wp core verify-checksums |
Ensures all core files match the original WordPress versions.
- Download a specific WordPress version.
| wp core download –version=6.3 |
Useful for testing or rolling back to the previous WordPress version.
Essential Commands for Plugins and Themes
Managing themes and plugins becomes faster and more efficient with WP-CLI.
Plugin Commands.
- List all installed plugins.
| wp plugin list |
Shows all installed plugins with their status (active/inactive).
- Install and activate a plugin.
| wp plugin install akismet –activate |
- Update all plugins.
| wp plugin update –all |
- Deactivate and delete a plugin.
| wp plugin deactivate akismet wp plugin delete akismet |
Theme Commands.
- List all installed themes.
wp theme list
- Install and activate a theme.
| wp theme install twentytwentyfive –activate |
- Update all themes.
| wp theme update –all |
- Delete a theme.
| wp theme delete twentytwentyone |
Adding, Editing, and Deleting Content
WP-CLI simplifies content management by allowing you to create, edit, and delete posts, pages, and custom post types from the command line.
Create a New Post or Page.
| wp post create –post_type=post –post_title=”My New Post” –post_status=publish |
Edit an existing Post.
| wp post update 123 –post_title=”Updated Title” |
Delete a Post or Page.
| wp post delete 123 –force |
List all Posts.
| wp post list |
Generate Dummy Content.
| wp post generate –count=10 |
Creates 10 random posts, useful for testing themes and plugins.
Importing and Exporting Data With Ease
Whether migrating a site or creating backups, WP-CLI offers straightforward commands for importing and exporting data.
Export Content.
| wp export –dir=/path/to/export |
Import Content.
| wp import /path/to/file.xml –authors=create |
Imports content from WordPress export files and creates authors if needed.
Database Export.
| wp db export /path/to/backup.sql |
Creates an SQL dump of your database.
Database Import.
| wp db import /path/to/backup.sql |
Restores a database from an SQL file.
Database and Security Management with WP-CLI
Handling Backups and Restorations
Backing up your database is one of the most essential tasks in WordPress management. The database contains critical information including posts, pages, user data, and site settings. Creating regular backups ensures you can recover your site quickly in case of any data loss, corruption, or unsuccessful updates.
With WP-CLI, the process is streamlined, you can create copies of your database in seconds and store them in a secure location for future use. Restoring backups is equally straightforward, enabling you to revert your site to a previous state with minimal downtime. This is helpful during migrations, major updates, or troubleshooting issues.
WP-CLI enables advanced users to integrate backup processes into automated workflows, ensuring backups happen regularly without manual intervention. Additionally, the tool can reset the database to a clean state, making it ideal for testing and starting over during development.
Running Security and Maintenance Commands
Regular maintenance and security checks are essential to protect your WordPress site. WP-CLI provides a set of commands to simplify these processes.
Commands for Security.
Check File Permissions.
| wp eval ‘var_dump(octdec(substr(sprintf(“%o”, fileperms(ABSPATH)), -4)));’ |
Ensure proper file permissions eg 755 for directories and 644 for files.
Run Core file integrity check.
| wp core verify-checksums |
Verifies the integrity of WordPress core files to ensure they haven’t been altered.
Force User Password Reset.
| wp user update 1 –user_pass=”newsecurepassword” |
Securely update user passwords, especially for administrators.
Commands for Maintenance.
Optimize Database.
| wp db optimize |
Cleans and optimizes the database for better performance.
Clear Cache.
| wp cache flush |
Clears WordPress cache to reflect recent updates.
Enable Maintenance Mode.
| wp maintenance-mode activate |
Temporarily disable the site for visitors while updates or changes are applied.
Disable maintenance mode.
| wp maintenance-mode deactivate |
Using WP-CLI for Multisite Management
Commands for Managing Multiple WordPress Sites
In a Multisite network, each site has its own set of content, plugins, themes, and configurations. WP-CLI allows you to effortlessly perform actions across the entire network or target specific sites.
Listing Sites in a Network.
| wp site list |
This provides details like Site ID, domain, path, and status.
Activating and deactivating plugins for a specific site.
| wp plugin activate plugin-name –url=site1.example.com wp plugin deactivate plugin-name –url=site2.example.com |
Switching themes for a specific site.
| wp theme activate theme-name –url=site3.example.com |
Creating a New Site.
| wp site create –slug=newsite –title=”New Site” –email=admin@example.com |
Deleting a Site.
| wp site delete 123 –yes |
Replace 123 with the site ID.
Troubleshooting a specific site.
| wp site info –url=site4.example.com |
View debug information for a particular site.
Resetting a Site.
| wp site empty –url=site5.example.com –yes |
To reset a site to its default state(clears all content)
These commands allow administrators to efficiently manage individual sites within a network without logging into each site’s admin panel, saving time and ensuring consistency.
Simplifying Multisite Updates and Configurations
Keeping a multisite network is key for security and performance. WP-CLI ensures that updates and configurations are easy and efficient.
Batch Updates. WP-CLI allows you to update core files, plugins, and themes across all sites in the network simultaneously. This ensures consistency and prevents outdated components from posing security risks.
Automated Maintenance. Regular maintenance tasks, such as database optimization or clearing transient data, can be scheduled and executed for all sites using WP-CLI scripts.
Configuration Management. WP-CLI lets you modify network settings directly from the command line, such as permalink structures, site titles, or admin emails. These changes can be applied to the entire network or individual sites.
Troubleshooting with WP-CLI
System Health Checks and Log Monitoring
System Health Checks.
With WP-CLI, you can review key aspects of your WordPress installation, such as the current version, active plugins, and theme integrity. These checks help verify that your site is properly configured and running the latest updates. Additionally, you can monitor database performance by inspecting table status or optimizing them for better efficiency.
You can review the PHP and database versions for server-related issues, ensuring compatibility with WordPress core and installed plugins/themes.
Login Monitoring
Tracking user login is pivotal for identifying unauthorized access or suspicious activity on your site. WP-CLI can assist in monitoring login events by generating user activity reports, resetting credentials, or disabling compromised accounts.
Besides that, WP-CLI helps troubleshoot issues where users face login difficulties due to misconfigurations, plugin conflicts, or incorrect role assignments.
Helpful Commands
List all Users.
| wp user list |
Reset a user’s password.
| wp user update 2 –user_pass=”newsecurepassword” |
Replace 2 with the use ID.
Lock or Disable the User Account.
| wp user update 3 –role=none |
Prevents a user from logging in.
Monitor Suspicious login activity.
| wp plugin command_here –logins |
Export user activity logs(if your site tracks logins using a plugin)
Debugging Tools and Techniques
When things go wrong on your WordPress site, finding the root cause quickly is vital. WP-CLI provides various commands and tools to help identify and resolve issues efficiently, whether it’s a plugin conflict, a misconfiguration, or a deeper problem with the core.
Debugging WordPress Core and Configurations.
With WP-CLI, you can enable debugging modes and access detailed logs directly from the command line. This eliminates the need to navigate through WordPress files manually, saving time and reducing complexity. By enabling debug logs, you can trace errors in themes, plugins, or server configurations, gaining insights into what is causing the behavior.
Debugging Commands
Enable Debugging Mode.
| wp config set WP_DEBUG true –raw wp config set WP_DEBUG_LOG true –raw |
This creates or updates your wp-config.php file to log errors into wp-content/debug.log
Disable Debugging Mode
| wp config set WP_DEBUG false –raw wp config set WP_DEBUG_LOG false –raw |
Once the issues have been resolved, disable debugging mode to improve performance.
Plugin and Theme Troubleshooting.
When a Plugin or theme is causing issues, WP-CLI lets you deactivate problematic components or switch to different themes without logging into the admin dashboard. This is very useful when the admin dashboard becomes inaccessible due to errors.
Database Debugging.
Corrupted or improperly configured database tables can cause performance bottlenecks or functional errors. WP-CLI enables you to inspect and repair database tables, ensuring smooth site functionality.
Database Commands.
- Check Database tables.
| wp db check |
- Repair Corrupted tab;les.
| wp db repair |
- Inspect Table data.
| wp db query “SELECT * FROM wp_posts LIMIT 10;” |
View the content of a specific database table.
Error Monitoring and Logs.
WP-CLI simplifies the process of reviewing error logs generated by WordPress or the server, making it easier to pinpoint problems. This is necessary when dealing with compatibility issues, slow-loading pages, or broken features.
Commands.
- View Debug Logs.
| wp shell — eval “file_get_contents(ABSPATH . ‘wp-content/debug.log’);” |
View the debug log file directly in the terminal.
- Check the Error log status.
| wp eval ‘var_dump(defined(“WP_DEBUG_LOG”) && WP_DEBUG_LOG);’ |
Ensure the debug log is functioning and accessible.
- Inspect Site Status.
| wp site status |
Use the Site Health tool to identify common issues.
By leveraging WP-CLI for debugging, you can identify and fix issues without accessing the WordPress admin interface. These tools empower developers and site administrators to maintain stable and reliable websites.
Conclusion
WP-CLI is a game-changer for WordPress management, offering speed, efficiency, and flexibility to developers and site administrators alike. From handling routine tasks like updates, backups, and plugin management to addressing complex issues like multi site configurations and debugging, WP-CLI simplifies the processes that would otherwise require significant time and effort through the WordPress admin dashboard.
Integrating WP-CLI into your workflow, especially with tools like InstaWP for staging and testing, can streamline site maintenance, improve productivity, and reduce downtime. Whether you’re managing a single site or an extensive network of WordPress installations, WP-CLI empowers you to take control of your sites with ease and precision.
Incorporating WP-CLI into your toolkit not only enhances your technical skills but also ensures you’re equipped to handle the dynamics of WordPress Site Management in a fast-paced digital environment. Now is the time to embrace the power of WP-CLI and elevate your WordPres development and management practices.
WP CLI FAQs
- What is WP-CLI, and why is it important?
WP-CLI is a command-line interface for WordPress that allows you to manage your site without using the web-based admin dashboard. It is significant for tasks like updating WordPress core, managing plugins and themes, and automating repetitive processes, making it a valuable tool for developers and administrators.
- Can I use WP-CLI to manage WordPress Multisite networks?
Yes, WP-CLI is ideal for managing multisite networks. It allows you to list sites, activate or deactivate plugins and themes on individual sites, and perform updates across the entire network. This reduces the manual work required for managing multiple sites.
- What are the System requirements for WP-CLI?
To use WP-CLI, you need;
- A server running PHP 7.4 or higher.
- A UNIX-based Operating System (Linux or macOS, Windows support may require additional configuration)
- WordPress 3.7 or higher.
- How can I set up WP-CLI on my system?
Setting up WP-CLI involves downloading the WP-CLI package, verifying the installation, and making the wp command globally accessible. Detailed setup instructions are available on the official WP-CLI website. For learning experimentation, using a staging environment like InstaWP is recommended.
- Can I troubleshoot WordPress using WP-CLI?
WP-CLI offers debugging tools to identify issues in plugins, themes, or the WordPress core. You can enable debugging logs, review error logs, and use commands to isolate and resolve problems. It also supports resetting configurations and repairing the database.
- Is WP-CLI safe to use on a live Website?
Yes, WP-CLI is safe for live sites if used cautiously. However, it is recommended to test commands in a staging environment first, especially for complex operations. InstaWP is a great platform for setting up a staging environment very quickly.
- How does WP-CLI simplify database management?
WP-CLI allows you to perform database operations like checking table health, repairing corrupted tables, optimizing performance, and importing or exporting data with simple commands. This makes database management faster and more reliable.
- How can WP-CLI be integrated with automation Workflow?
WP-CLI commands can be integrated into scripts and scheduled using cron jobs or task automation tools. This allows you to automate tasks like backups, updates, and maintenance, saving time and ensuring consistency across sites.