When managing a WordPress site, most people often rely on the default admin dashboard. While it works well, it can feel slow and limited when you need to perform repetitive or bulk tasks. That’s where WP-CLI comes in, a powerful command-line tool that makes WP management faster, more efficient, and scriptable.
What is WP-CLI
WP-CLI (WordPress Command Line Interface) is an open-source tool that lets you control and manage WP websites directly from the terminal. Instead of clicking through the admin dashboard, you can run terminal commands to update plugins, manage users, export data, and much more.
It’s especially useful for developers, sysadmins, and agencies managing multiple sites, as it enables automation and integration with server scripts or deployment workflows.
WP-CLI Features
WP-CLI can manage all the aspects that you usually do inside the admin dashboard. It can even handle a wide range of server-side tasks, such as flushing WP cache, editing WP config, managing WP-Cron events, and mass updating plugins across multiple WP sites with just a single command.
For example:
| Command | Description |
|---|---|
wp core update | Updates WP to a newer version. |
wp plugin list | List all plugins. |
wp plugin update --all | Update all plugins. |
wp cache flush | Flush the object cache. |
wp db export | Export the database to a file. |
wp config list | List constants and variables defined in wp-config.php file. |
For a complete list of available commands, check the official documentation.
Each command includes a set of parameters that you can combine to perform more specific tasks.
How to Install WP-CLI
Connect to your server via SSH.
Download wp-cli.phar:
sudo curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Code language: plaintext (plaintext)
Move the downloaded file to /usr/local/bin/wp:
sudo mv wp-cli.phar /usr/local/bin/wpCode language: plaintext (plaintext)
Make that file executable:
sudo chmod +x /usr/local/bin/wpCode language: plaintext (plaintext)
To confirm that the installation was successful, run the following command to view WP-CLI details:
wp --infoCode language: plaintext (plaintext)
If you see something like below, then your installation was successful:
OS: Linux...
Shell: /bin/bash
PHP binary: /usr/bin/php...
PHP version: ...
php.ini used: /etc/php/...
MySQL binary: /usr/bin/...
MySQL version: ...
SQL modes:
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: phar:///usr/local/bin/wp
WP-CLI packages dir:
WP-CLI cache dir: /home/ubuntu/.wp-cli/cache
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.12.0Code language: plaintext (plaintext)
How to Use WP-CLI
To use WP-CLI, you must navigate to your WordPress installation directory first by using cd command. For example:
cd /var/www/public/wordpressCode language: plaintext (plaintext)
Then, you can begin to use wp commands from there.
Be aware: If your wp-config.php file has strict permissions (for example, 400 or 640), running WP-CLI commands may trigger the following error:
PHP Warning: file_get_contents(/var/www/public/wordpress/wp-config.php): Failed to open stream: Permission denied in phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php on line 712
Error: Strange wp-config.php file: wp-settings.php is not loaded directly.
Code language: plaintext (plaintext)
The solution is to run WP-CLI commands with sudo and specify the web server user (usually www-data) before the wp command. For example:
sudo -u www-data wp plugin listCode language: plaintext (plaintext)
Now you’re ready to use WP-CLI to manage your WordPress sites.