Install WP-CLI
At the end you will be able to type wp on your server or computer and run WP-CLI commands such as wp db export and wp search-replace against a WordPress site.
What you need before step 1
Applies to: WP-CLI 2.x with PHP 7.2.24 or later on Linux, macOS and Windows (as documented in the WP-CLI handbook)
Admin roles you need
- SSH access to the web server (or a terminal on your own computer for a local site)
- sudo rights to move the file into /usr/local/bin. Without sudo, put it in a folder in your own PATH such as ~/bin
Licences
None needed.
Download
https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.pharDownloadInstall instructions
https://make.wordpress.org/cli/handbook/guides/installing/Install stepsReference documentation
https://make.wordpress.org/cli/handbook/guides/verifying-downloads/ReadAlso have ready
- PHP 7.2.24 or later on the command line (check with php --version)
- Outbound HTTPS to GitHub for download and updates
- Check whether your host already provides WP-CLI: if wp --info works over SSH, skip to the verify step
8 steps
- 1
Check PHP and whether wp already exists
Where: SSH session to the web server, or Terminal on macOS/LinuxRun both commands. If
wp --infoalready prints WP-CLI details, WP-CLI is installed and you can stop here.php --version wp --infoYou should see: PHP reports version 7.2.24 or later. wp --info either prints WP-CLI details or "command not found". - 2
Download wp-cli.phar
Where: The same terminal, in your home directoryDownload the Phar file from the URL in the WP-CLI handbook.
cd ~ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.pharYou should see: curl shows a progress bar and wp-cli.phar is saved in your home directory. - 3
Optional: check the download is genuine
Where: The same terminalDownload the published SHA-512 checksum and compare it with the hash of your file. The handbook also documents a stronger GPG signature check.
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar.sha512 sha512sum wp-cli.phar cat wp-cli.phar.sha512You should see: The two hash values match exactly. - 4
Test that the Phar runs
Where: The same terminalRun the file with PHP before installing it.
php wp-cli.phar --infoYou should see: Output listing OS, Shell, PHP binary, PHP version, php.ini used and WP-CLI version. - 5
Make it executable and move it onto your PATH
Where: The same terminalMake the file executable and move it to
/usr/local/bin/wpso you can typewpfrom anywhere. Enter your password if sudo asks.chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wpYou should see: No output. The commands return to the prompt. - 6
macOS alternative: install with Homebrew
Where: Mac: Finder > Applications > Utilities > Terminal (Homebrew installed from https://brew.sh)Instead of downloading the Phar and moving it yourself you can install with Homebrew.
brew install wp-cliYou should see: Homebrew installs wp-cli and the wp command is available. - 7
Windows: install PHP and create wp.bat
Where: Windows PC, File Explorer and Command PromptInstall PHP and add it to your PATH. Create the folder
C:\wp-cliand downloadwp-cli.pharinto it from the URL above. In that folder create a text file namedwp.batcontaining the two lines below, then add the folder to your PATH withsetxand open a new Command Prompt. The handbook notes wp.bat does not work in Git Bash; there you need an extensionlesswpscript instead.@ECHO OFF php "c:/wp-cli/wp-cli.phar" %* setx path "%path%;c:\wp-cli"You should see: In a new Command Prompt, wp --info prints WP-CLI details. - 8
Run a first command against your site
Where: SSH session, in the WordPress folder (the one containing wp-config.php), as the site's own user rather than rootChange to the WordPress folder and check the site's home URL.
cd /var/www/contoso.com/public_html wp option get homeYou should see: The site address is printed, for example https://contoso.com.
Expert tips
If a broken plugin or theme stops WP-CLI loading, run the command with --skip-plugins --skip-themes, or skip just one, for example --skip-plugins=akismet. This is how you deactivate the bad plugin when the dashboard is down: wp plugin deactivate <name> --skip-plugins.
The global --debug flag shows all PHP errors and the WP-CLI bootstrap steps, which usually reveals a missing PHP extension or a failing wp-config.php include.
Servers often have several PHP versions. wp --info shows the PHP binary and version WP-CLI runs with, which may differ from the version the website uses.
Register aliases such as @prod and @dev in the project's wp-cli.yml or your global ~/.wp-cli/config.yml, each with an ssh: value like user@host/path. During a migration you can then run wp @prod option get home and wp @dev option get home from one terminal.
How to confirm it worked
Run
wp --info. The handbook says output showing the WP-CLI version means the install succeeded.In the WordPress folder,
wp option get homeprints the site address.
How to reverse it
Delete the file: sudo rm /usr/local/bin/wp (Phar install), brew uninstall wp-cli (Homebrew), or delete C:\wp-cli and remove it from PATH (Windows). WP-CLI does not change your WordPress site by being installed.
Errors you might see
wp: command not foundCause: The Phar was not moved into a folder in PATH, or (over SSH) the remote server has no wp on its PATH.
Fix: Move it to /usr/local/bin/wp, or for remote use set WP_CLI_SSH_BINARY to the command name or path, as the troubleshooting guide describes.
Parse error in wp-config.phpCause: The file is saved with the wrong encoding.
Fix: Save wp-config.php as UTF-8 without BOM.
PHP Fatal error from wp-config.phpCause: wp-config.php calls WordPress functions, which fails when WP-CLI loads it.
Fix: Keep only constant definitions in wp-config.php and keep the require_once(ABSPATH . 'wp-settings.php'); line.
Install or wp cli update hangsCause: Outbound connections to GitHub are blocked.
Fix: Allow outbound connections to GitHub on port 443.
Questions
How do I update WP-CLI?
Run wp cli update (with sudo if the file is in /usr/local/bin). Add --nightly for the nightly build.
What PHP version does WP-CLI need?
The handbook says PHP 7.2.24 or later.
Does my host already have WP-CLI?
Some hosts provide it over SSH already. Run wp --info to check before installing your own copy.
Can I run WP-CLI against a remote server from my PC?
Yes, with the global --ssh=user@host/path parameter, but the handbook says WP-CLI must also be installed on the remote server and callable as wp.
Official sources
Vendors change menus and requirements. Confirm on the source before you rely on a detail. Last checked 4 Nov 2026.
