For the complete documentation index, see llms.txt. This page is also available as Markdown.

How to install and use WP-CLI

WP-CLI is a command-line tool for managing WordPress sites. Instead of logging into the admin dashboard for every small task, you can manage updates, plugins, users, and content directly from the terminal. It is faster and perfect for automation.

Step 1: Download WP-CLI

cd /tmp
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Step 2: Make it executable and move it to PATH

chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Verify it works:

wp --info

You should see version and environment details.

Step 3: Install WordPress (if not already installed)

Navigate to your web directory and download WordPress:

cd /var/www/example.com/html
wp core download

Create the wp-config file:

wp config create --dbname=mydb --dbuser=myuser --dbpass=mypassword --dbhost=localhost

Run the installation:

That is it. Your WordPress site is now ready.

Step 4: Manage plugins

List all installed plugins:

Install a plugin:

Update all plugins:

Deactivate a plugin:

Step 5: Manage themes

List themes:

Install and activate a theme:

Step 6: Manage users

List users:

Create a new user:

Step 7: Update WordPress core

Always update the database after updating the core.

Step 8: Useful WP-CLI commands for everyday work

Command
What it does

wp cache flush

Clear all cache

wp search-replace 'old.com' 'new.com'

Update URLs in the database (useful for migrations)

wp db export

Export the database to a SQL file

wp db import file.sql

Import a database

wp post list

List recent posts

wp media list

Show uploaded media

wp option get siteurl

Get the site URL setting

wp rewrite flush

Flush rewrite rules

Step 9: Set up cron for WordPress

WordPress has its own cron system, but it only runs when someone visits the site. For better reliability, disable WP cron and use the system cron instead.

Add this to wp-config.php:

Then set up a system cron job:

Add this line to run every 15 minutes:

Step 10: Keep WP-CLI updated

WP-CLI can update itself:

Common tasks by example

Reset a forgotten password:

Bulk update all plugins and themes:

Check WordPress health:

Export and import content:

Common issues

"Error: This does not seem to be a WordPress site" Navigate to the WordPress root directory first. WP-CLI needs to find the wp-config.php file.

"Error: Too many redirects" This usually means the site URL is misconfigured. Check it with wp option get siteurl and wp option get home.

Permission errors Make sure the web server user can read and write WordPress files. On Ubuntu with Nginx, that is usually www-data.

Security tips

  • Do not use --user_pass in commands that get logged to shell history. Use wp user create interactively instead.

  • Keep WP-CLI and WordPress core updated.

  • Limit WP-CLI access to trusted users on the server.

Conclusion

WP-CLI turns hours of clicking into seconds of typing. Once you get used to managing WordPress from the terminal, going back to the admin dashboard feels slow.

Last updated