Overview
WordPress Command Line Interface (wp-cli) is a command-line tool installed on all DreamHost servers. It allows you to run WordPress commands from your Shell terminal to manage your WordPress site without logging in to the WordPress dashboard.
Prerequisites
This article assumes you have Created a Shell user and are able to log into your server via SSH.
After you're logged in to your server, make sure you’re in your website’s directory. This is where you'll run all the commands in this article.
General commands
These are a few general commands to get you started.
View all wp-cli commands
[server]$ wp
A list of all available commands displays.
Using --help to view command information
To get more information on a specific command, run the --help option.
[server]$ wp plugin --help
This prints a list of available subcommands. You can then add one of these subcommands to the main command to perform an action. Here is how you’d install a plugin named hello-dolly:
[server]$ wp plugin install hello-dolly
wp cli version
Action | Command |
---|---|
View the wp-cli version |
[server]$ wp cli version |
Check for updates |
[server]$ wp cli check-update |
Update wp-cli |
[server]$ wp cli update |
Top commands
These commands are the most commonly used.
Plugins
Obtaining the correct name of the plugin
The name you use when entering the PLUGIN_NAME must be the name from the plugin site's web page. For example, if you wanted to install W3 Total Cache you'd visit this page:
You can see it ends with w3-total-cache. This is the plugin name you would enter in the commands below.
Action | Command |
---|---|
View installed plugins |
[server]$ wp plugin list |
Install a plugin |
[server]$ wp plugin install PLUGIN_NAME |
Activate a plugin |
[server]$ wp plugin activate PLUGIN_NAME |
Deactivate a plugin |
[server]$ wp plugin deactivate PLUGIN_NAME
[server]$ wp plugin toggle PLUGIN_NAME |
Themes
Action | Command |
---|---|
View installed themes |
[server]$ wp theme list |
Install a theme |
[server]$ wp theme install THEME_NAME |
Activate a different theme |
[server]$ wp theme activate THEME_NAME |
Update a theme |
[server]$ wp theme update THEME_NAME |
Updating WordPress
Action | Command |
---|---|
View the current WordPress version |
[server]$ wp core version |
Check for WordPress version updates |
[server]$ wp core check-update |
Update WordPress to a newer version |
[server]$ wp core update |
Force download of all core files. This re-downloads the core WordPress files and overwrites any core files that already exist. |
[server]$ wp core download --force |
Creating users
Action | Command |
---|---|
View a list of all current users |
[server]$ wp user list |
Create a new username while assigning its email and role. A new password is printed to the terminal after the user is created. |
[server]$ wp user create newusername admin@example.com --role=administrator |
Changing a password
Action | Command |
---|---|
Run wp user list to obtain a user's ID#. Use that user ID# to update their password. This example is changing a user with an ID# of 3. You would then need to inform the user of their password change. |
[server]$ wp user update 3 --user_pass=NEW_PASSWORD |
Deleting a user
Action | Command |
---|---|
Run wp user list to obtain the ID# of the user you wish to delete and the user you wish to reassign its posts. You'll need to to reassign any posts to another user so they are not permanently deleted. This example deletes a user with an ID# of 13 and reassigns their posts to user 7. |
[server]$ wp user delete 13 --reassign=7 |
Troubleshooting commands
Cache
Action | Command |
---|---|
Flush your site's cache |
[server]$ wp cache flush |
Clear the wp-cli cache |
[server]$ wp cli cache clear |
Database
Action | Command |
---|---|
Check the status of the database |
[server]$ wp db check |
Optimize the database |
[server]$ wp db optimize |
Repair the database |
[server]$ wp db repair |
Search for text in the database. This searches for the word hello. |
[server]$ wp db search hello |
Upgrade the database version |
[server]$ wp core update-db |
Permalinks
Action | Command |
---|---|
Flush permalinks. This is the same as re-saving them in the dashboard. |
[server]$ wp rewrite flush |
Custom changes
Updating the home and siteurl
Action | Command |
---|---|
View the home and siteurl |
[server]$ wp option list | grep -E "^(siteurl|home)" |
Update the home url |
[server]$ wp option update home https://example.com |
Update the siteurl |
[server]$ wp option update siteurl https://example.com |
Importing and exporting a WXR file
You can use the import and export commands to manage your site data with a WXR file. See this article for details.
Search and Replace
Search and replace text in your database. Make sure to use the --dry-run flag the first time to see what will change.
[server]$ wp search-replace http://example.com https://example.com/blog --dry-run
A list of fields that will be updated displays in your terminal. If you'd like to update all output displayed, run the command again without the --dry-run flag.
[server]$ wp search-replace http://example.com https://example.com/blog
wp-config.php
Action | Command |
---|---|
View all settings in your wp-config.php file |
[server]$ wp config list |
Update a setting in your wp-config.php file. This updates the DB_HOST value. |
[server]$ wp config set DB_HOST mysql.example.com |
Updating the PHP version wp-cli uses
- View the current version of PHP and its location by running the following command:
[server]$ wp cli info
- To change the version of PHP wp-cli uses, add the following line to your .bash_profile. Change the version as needed. This example uses PHP 8.2.
export WP_CLI_PHP=/usr/local/php82/bin/php wp
- Update the .bash_profile:
[server]$ . ~/.bash_profile
- Check to confirm wp-cli is using this new version.
[server]$ wp cli info PHP binary: /usr/local/php82/bin/php PHP version: 8.2
See also
- wp-cli.org – Official WP CLI website
- wp-cli commands
- How to log into your WordPress site
- WordPress overview