WP-CLI is the official command-line tool for WordPress management. It lets you automate tasks such as creating users, updating plugins, and changing site settings directly on your server.
Basic installation requirements
Before starting, make sure you have:
- PHP CLI: working
php-clipackage. - Shell access: root/sudo or jailed shell.
- Download tool:
curl,wget, or equivalent.
1. Standard installation (with root/sudo)
Recommended method to run wpcli globally from anywhere in terminal.
Step 1: download WP-CLI
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Step 2: make it executable
chmod +x wp-cli.phar
Step 3: move to global command path
sudo mv wp-cli.phar /usr/local/bin/wpcli
Verification
wpcli --info
If you get WP-CLI, PHP, and OS details, installation is successful.
2. Local installation (without root/sudo)
For jailed shell environments, install inside your user path.
Step 1: create local binary directory
mkdir ubin
Step 2: download WP-CLI
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Step 3: make it executable
chmod +x wp-cli.phar
Step 4: move to local directory
mv wp-cli.phar ubin/wpcli
How to run it
ubin/wpcli
Warning: even from a subdirectory,wpcliwill try to locatewp-config.phpto connect to your WordPress installation.
Essential WP-CLI commands
| Category | Task | Example |
|---|---|---|
| Plugins | List plugins | wpcli plugin list |
| Plugins | Activate plugin | wpcli plugin activate [slug] |
| Plugins | Install plugin | wpcli plugin install [slug] |
| Users | List users | wpcli user list |
| Users | Create user | wpcli user create NAME EMAIL --role=ROLE --user_pass=PASSWORD |
| Users | Delete user | wpcli user delete ID |
| Database | Export backup | wpcli db export backup.sql |
| Database | Import backup | wpcli db import backup.sql |
| Database | Optimize/Repair | wpcli db optimize / wpcli db repair |
| Updates | Update core | wpcli core update |
| Updates | Update all plugins | wpcli plugin update --all |
| Updates | Update all themes | wpcli theme update --all |
| Configuration | Generate wp-config.php | wpcli core config --dbname=DB --dbuser=USER |
| Configuration | Install WordPress | wpcli core install --url=DOMAIN --title=TITLE |
The biggest WP-CLI advantage is operational speed plus easy automation for maintenance workflows.
This post is licensed under CC BY-NC.
Comments
Join the discussion below.
Comments are not configured yet. Add Cusdis settings in /assets/json/config/blog-comments-config.json.