Step 1: Getting Started If WP-CLI Is Already Installed
Many hosts pre-install WP-CLI, so check first to avoid reinventing the wheel. You’ve verified it’s there via File Manager—awesome! Now, let’s fire it up.
Access Your cPanel Terminal
- Log into cPanel (usually yourdomain.com/cpanel).
- Head to the Advanced section and click Terminal (or enable SSH under Security > SSH Access).
- Boom—a shell prompt like [username@server ~]$ awaits.
Navigate to Your WordPress Root
Your site’s files live in public_html (or a subfolder like public_html/blog).
- Run: cd public_html
- Confirm with ls—you should spot wp-config.php and wp-content/.
Verify and Test WP-CLI
In your WordPress directory:
wp --info
This spits out version details. If it works, test with:
wp core version
(Should show your WP version, e.g., “6.4.2”.)
If you get “command not found,” it’s likely a PATH issue—jump to the installation section below.
Your First Commands: Baby Steps to Power
Start simple. Run wp help for the full menu. Here are essentials:
- Site Health Check: wp doctor check –all (flags issues like outdated plugins).
- List Plugins: wp plugin list (shows active/inactive ones).
- Install & Activate a Plugin (e.g., Yoast SEO): wp plugin install yoast-seo –activate.
- Update Core: wp core update (add –yes to skip prompts).
- List Themes: wp theme list.
- Create a Post: wp post create –post_title=”Hello WP-CLI!” –post_content=”This was made via terminal!” –post_status=publish –post_type=post.
For command-specific help: wp plugin help.
Step 2: Installing WP-CLI from Scratch (For Newbies)
No pre-install? No problem. This user-level setup takes ~5 minutes. Prerequisites: PHP 7.4+ (check with php -v) and terminal access.
Download the PHAR File
From your home directory (or WordPress root):
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Make It Executable
chmod +x wp-cli.phar
Verify: ls -l wp-cli.phar (look for executable perms like -rwxr-xr-x).
Test the Install
./wp-cli.phar --info
Or via PHP: php wp-cli.phar –info. It should detect your WP setup.
Go Global: Easy Access Everywhere
To run wp without ./wp-cli.phar:
- mkdir -p ~/bin
- mv wp-cli.phar ~/bin/wp
- Add to PATH: export PATH=~/bin:$PATH
- Make it permanent: Edit ~/.bashrc with nano ~/.bashrc, add export PATH=~/bin:$PATH at the end, save (Ctrl+O > Enter > Ctrl+X), then source ~/.bashrc.
Now, wp –info works anywhere!
Bonus: Enable Autocomplete
Tab-complete commands like a boss:
- curl -O https://raw.githubusercontent.com/wp-cli/wp-cli/master/utils/wp-completion.bash
- mv wp-completion.bash ~/
- Add to ~/.bash_profile: source ~/wp-completion.bash (edit, save, source ~/.bash_profile).
Pro Tips for WP-CLI Mastery
- Backups First: wp db export backup.sql before big changes.
- Aliases for Laziness: In ~/.bashrc, add alias w=’wp’ and reload.
- Verbose Mode: Add –verbose for details (e.g., wp core update –verbose).
- Multisite Sites: Target subsites with –url=your-subsite.com.
- Exit Gracefully: Type exit when done.