What is WP-CLI? #
WP-CLI, short for WordPress Command Line Interface, is a powerful tool that can be used to manage and maintain your WordPress website from the command line. It offers users a plethora of commands for various functions, like plugin installation, backup generation, core file updating, and many more.
Daniel Bachhuber has been the primary maintainer of the open source project known as ‘WordPress Command Line Interface (or, for short: ‘WP-CLI’) since 2003.
On August 8th, 2018, the new version of the WordPress Command Line Interface (known as “WPC-CLI v2”) became available.
For Tarweig customers, WP-CLI version 2.7.1 is readily available on all our Managed WordPress hosting plans; all you need to do is access your account via SSH, and you are good to go!
Installing WP-CLI #
The instructions below will be helpful if you don’t have WP-CLI installed on your server. It is essential to ensure your system meets the necessary requirements before installing it. Specifically, users must have a UNIX-like environment (including OS X, Linux, FreeBSD, or Cygwin) and partial support in Windows environments. Moreover, they should have PHP 5.6+ and WordPress 3.7+; however, note that older versions of WordPress may provide lesser functionality.
Once you’ve verified the requirements, download the wp-cli.phar file using wget or curl:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Next, check the Phar file to verify that it’s working:
php wp-cli.phar --info
To use WP-CLI from the command line by typing wp, make the file executable and move it somewhere in your PATH. For example:
chmod +x wp-cli.phar\nsudo mv wp-cli.phar /usr/local/bin/wp
If it was installed successfully, you should see something like this when you run wp --info:
[root@rs9-nyc ~]# wp --info\nOS: Linux 4.18.0-425.10.1.lve.el7h.x86_64 #1 SMP Wed Jan 25 09:29:40 EST 2023 x86_64\nShell: /bin/bash\nPHP binary: /opt/cpanel/ea-php72/root/usr/bin/php\nPHP version: 7.2.34\nphp.ini used: /opt/cpanel/ea-php72/root/etc/php.ini\nMySQL binary: /usr/bin/mysql\nMySQL version: mysql Ver 15.1 Distrib 10.5.19-MariaDB, for Linux (x86_64) using readline 5.1\nSQL modes:\nWP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli\nWP-CLI vendor dir: phar://wp-cli.phar/vendor\nWP_CLI phar path: /root\nWP-CLI packages dir:\nWP-CLI cache dir: /root/.wp-cli/cache\nWP-CLI global config:\nWP-CLI project config:\nWP-CLI version: 2.7.1
For those using Tarweig Managed WordPress hosting, WP-CLI is available right away. Don’t know what version you’re working with? Utilize the wp cli version command to get an answer.
[root@rs9-nyc ~]# wp cli version --allow-root\nWP-CLI 2.7.1
Updating WP-CLI #
You can update WP-CLI by using wp cli update or repeating the installation steps.
If WP-CLI is owned by root or another system user, you’ll need to run sudo wp cli update.
Managing WordPress #
Beginning a command requires wp followed by the desired command, subcommand, and essential and nonessential parameters.
Keep in mind that whatever WordPress directory you are in the terminal is what WP-CLI will work with. If you are using cPanel as the control panel, here’s a great guide on how to find the document root of your WordPress website in cPanel. So, for instance, changing directories to enter a different one may cause you to use another installation of WordPress.
Now let’s explore some practical WP-CLI commands as well as associated examples.
Installing WordPress #
To easily install WordPress using WP-CLI, here’s a list of commands that you should use:
# Download WordPress\n$ wp core download\nDownloading WordPress 6.2 (en_US)...\nmd5 hash verified: 34f279efe623025641bc11a69e3c02fa\nSuccess: WordPress downloaded.\n$ wp core download --locale=nl_NL\nDownloading WordPress 4.5.2 (nl_NL)...\nmd5 hash verified: c5366d05b521831dd0b29dfc386e56a5\nSuccess: WordPress downloaded.
By default, WordPress will be installed using the en_US locale code. In case you wish to install WordPress in a different language, you can use the --locale flag:
$ wp core download --locale=nl_NL\nDownloading WordPress 6.2 (nl_NL)...\nmd5 hash verified: 34f279efe623025641bc11a69e3c02fb\nSuccess: WordPress downloaded.
Here’s a great guide containing a list of all the WordPress Locale codes. (Hint – You can CRTL / CMD + F to find your language).
The second command will set up the wp-config.php configuration file with the database connection details. If you are using cPanel, make sure to create a database first.
$ wp core config --dbname=database_name --dbuser=database_username --dbpass=database_password --dbhost=localhost --dbprefix=mywp_\nSuccess: Generated 'wp-config.php' file.
The third command will install WordPress using a couple of parameters:
# Install WordPress\n$ wp core install --url=yourdomain.com --title="My WebSite Title" --admin_user=john.smith --admin_password=strongpassword [email protected]\nSuccess: WordPress installed successfully.
Reinstalling WordPress #
You can reinstall WordPress core files using WP-CLI. The following command would download WordPress core without the default themes and plugins.
wp core download --skip-content --force
Running WordPress Core Updates #
wp core version
# Display the WordPress version\n$ wp core version\n6.2\n
wp core check-update
# Check for WordPress updates\n$ wp core check-update\nSuccess: WordPress is at the latest version.
wp core update
# Update WordPress to a newer version\n$ wp core update\nUpdating to version 6.2 (en_US)...\nDownloading update from https://downloads.wordpress.org/release/wordpress-6.2-new-bundled.zip...\nUnpacking the update...\nCleaning up files...\nNo files found that need cleaning up.\nSuccess: WordPress updated successfully.\n
Rollback WordPress to a Previous Version #
First, you’ll need to check on the previous WordPress version. You can find all the available versions here.
Suppose you want to roll back WordPress to the 6.0.3 version. The wp-cli command line that you should use is:
wp core update --version=6.0.3 --force
Checking for Missing or Modified WordPress Core Files #
wp core verify-checksums – this command verifies WordPress files against WordPress.org’s checksums. It is handy if you suspect your WordPress might be infected with malware or if there are missing WordPress core files.
$ wp core verify-checksums\nWarning: File should not exist: wp-admin/error_log\nSuccess: WordPress installation verifies against checksums.
Managing Plugins #
Using wp plugin you can easily manage plugins, including installs, activations, and updates.
wp plugin list – get a list of installed WordPress plugins:
$ wp plugin list\n+---------+----------+--------+---------+\n| name | status | update | version |\n+---------+----------+--------+---------+\n| akismet | inactive | none | 5.1 |\n| hello | inactive | none | 1.7.2 |\n+---------+----------+--------+---------+
If you want to see only a list of all active plugins which have updates available, you can use the following:
wp plugin list --field=name --status=active --update=available
wp plugin install – installs one or multiple WordPress plugins
To find the plugin names, you can visit the WordPress Repository and check out the URL. This is an easy way to get the name of a plugin from its repository.

Alternatively, you can use wp plugin search searchterm which will give you a list of the slugs in the terminal.

# Install the latest version of the plugin and activate it:\n$ wp plugin install jetpack --activate\nInstalling Jetpack – WP Security, Backup, Speed, & Growth (12.0)\nDownloading installation package from https://downloads.wordpress.org/plugin/jetpack.12.0.zip...\nUnpacking the package...\nInstalling the plugin...\nPlugin installed successfully.\nActivating 'jetpack'...\nPlugin 'jetpack' activated.\nSuccess: Installed 1 of 1 plugins.
Another remarkable feature of WP-CLI is that it allows you to install WordPress plugins from remote files, not just the repository. This is incredibly useful when you’re working on a plugin or using a premium plugin.
$ wp plugin install http://s3.amazonaws.com/bucketname/my-plugin.zip?AWSAccessKeyId=123&Expires=456&Signature=abcdef --activate\nDownloading install package from http://s3.amazonaws.com/bucketname/my-plugin.zip?AWSAccessKeyId=123&Expires=456&Signature=abcdef\nUnpacking the package...\nInstalling the plugin...\nPlugin installed successfully.\nSuccess: Installed 1 of 1 plugins.
To install multiple WordPress plugins, you can pile on parameters. Here’s an example that downloads and activates 3 plugins:
# Install multiple plugins:\nwp plugin install really-simple-ssl seo-by-rank-math litespeed-cache --activate
In some cases, installing a previous version of WordPress plugins may be necessary. To do so, use the --version= flag
wp plugin install seo-by-rank-math --version=1.0.110 --activate
To get a previous version of a plugin, the first thing to do is search for the plugin in the WordPress repository. Scroll down on the plugin’s page and click on the “Advanced View.”
Scroll to the bottom of the page, and you will see an option to download previous versions of the plugin:

To deactivate a single plugin, you can run the following command:
$ wp plugin deactivate jetpack\nPlugin 'jetpack' deactivated.\nSuccess: Deactivated 1 of 1 plugins.
In the event of compatibility issues, it can be helpful to deactivate all plugins at once. Utilizing the command below makes it possible to do so quickly and easily. Afterward, you can reactivate them individually while testing for any conflicts.
To deactivate all your plugins at once, run the following command:
$ wp plugin deactivate --all\nPlugin 'hello' deactivated.\nSuccess: Deactivated 1 of 3 plugins.
You can also manually update WordPress plugins. Example below:
$ wp plugin update jetpack\nSuccess: Plugin already updated.
Additionally, you can update all your WordPress plugins. Example below:
$ wp plugin update --all\nSuccess: Plugin already updated.
Finally, you can also manually remove a WordPress plugin using the following command:
$ wp plugin delete jetpack\nDeleted 'jetpack' plugin.\nSuccess: Deleted 1 of 1 plugins.
Managing a WordPress Database #
wp db performs basic database operations using credentials stored in wp-config.php.
wp db export exports the database to a file.
$ wp db export\nSuccess: Exported to 'cchostingdemos_wp342-2023-04-24-50121f9.sql'.
wp db import imports a database from a file.
$ wp db import cchostingdemos_wp342-2023-04-24-50121f9.sql\nSuccess: Imported from 'cchostingdemos_wp342-2023-04-24-50121f9.sql'.
wp db optimize optimizes the database.
$ wp db optimize\nSuccess: Database optimized.
wp db repair repairs the database.
$ wp db repair\nSuccess: Database repaired.
wp db reset removes all tables from the database.
$ wp db reset\nAre you sure you want to reset the 'cchostingdemos_wp342' database? [y/n] y\nSuccess: Database reset.
wp db search finds a string in the database.
$ wp db search "[email protected]"\nmywp_options:option_value\n6:[email protected]\nmywp_users:user_email\n1:[email protected]
wp db size displays the database name and size.
$ wp db size\n+----------------------+----------+\n| Name | Size |\n+----------------------+----------+\n| cchostingdemos_wp342 | 704512 B |\n+----------------------+----------+
wp db size --tables displays the database tables and size for each.
$ wp db size --tables\n+-------------------------+---------+\n| Name | Size |\n+-------------------------+---------+\n| mywp_usermeta | 49152 B |\n| mywp_users | 65536 B |\n+-------------------------+---------+
wp db tables lists the database tables.
$ wp db tables\nmywp_commentmeta\nmywp_comments\nmywp_links\nmywp_options\nmywp_postmeta\nmywp_posts\nmywp_term_relationships\nmywp_term_taxonomy\nmywp_termmeta\nmywp_terms\nmywp_usermeta\nmywp_users
Managing WordPress Users #
wp user manages users and their roles, capabilities, and meta.
The following command will list all the users on your WordPress install:
# List users\nwp user list\n# List users with administrator role\nwp user list --role=administrator\n
The following command will create a new user on your WordPress install. The available roles are administrator, editor, author, contributor, and subscriber.
# Create a new administrator user.\nwp user create john [email protected] --role=administrator\nSuccess: Created user 5.\nPassword: C2p0MS4zCa
The following command will delete the user and re-assign all posts to another user:
# Delete user john and reassign posts to user paul\n$ wp user delete john --reassign=paul
By following the below steps, you will manage to reset the password for a specific WordPress user
Step 1: List all the users and find the ID of the user you'd like to change password:\n$ wp user list\n\nStep 2: Change password for specified user ID:\n$ wp user update 1 --user_pass=2DeBa10XjxD3Z8Ma\nreplace "1" with the id of the user you want to change password.
The following command will help you change the email address for a specific WordPress user:
Step 1: $ wp user list\n# to see all users. Find the ID of the user you'd like to update email address\n\nStep 2: update the email address:\n$ wp user update 1 --user_email=<email> replacing "1" with the id of the user you want to update and <email> with the new email address.
The following command will help you set or modify a WordPress user role:
Step 1: \n$ wp user list \n# to see all users. Find the ID of the user you'd like to update.\n\nStep 2:\n$ wp user set-role 1 administrator\nSuccess: Added johndoe (1) to http://example.com as author. \n\n# Available roles:\nadministrator\neditor\nauthor\ncontributor\nsubscriber
Performing a WordPress Database Search and Replace #
wp search-replace searches and replaces strings in the database. e.g.: replacing any match of an old domain name with a new domain name.
Before running this command, we strongly recommend you do a backup for your database using the following command line:
wp db export
Once you’ve ensured that you have a backup for the database, you can safely use the wp search-replace command:
wp search-replace 'https://old-domain.com/' 'http://new-domain.com/' --precise --recurse-objects --all-tables-with-prefix
| Parameter | Description |
|---|---|
| –precise | Force using PHP (instead of SQL), which is more thorough but slower. |
| –recurse-objects | Enable recursing into objects to replace strings. |
| –all-tables-with-prefix | Enable replacement on any tables that match the table prefix even if not registered on $wpdb. |
Using wp maintenance-mode You can control the maintenance mode on your WordPress site. Example:
wp cron event list
This command displays all scheduled cron events with their hook names, next run time, and recurrence.
To run a specific cron event immediately:
wp cron event run <hook>