How-to · WordPress

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.

Updated 4 Nov 20268 steps4 official sources
Before you start

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

wp-cli.pharThe download URL given in the WP-CLI handbookhttps://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.pharDownload

Install instructions

WP-CLI installation guide (WP-CLI handbook)Official install instructions, including Homebrew and Windowshttps://make.wordpress.org/cli/handbook/guides/installing/Install steps

Reference documentation

Verifying WP-CLI downloads (WP-CLI handbook)Optional signature checkhttps://make.wordpress.org/cli/handbook/guides/verifying-downloads/Read

Also 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
SiteGround web hosting
Step by step

8 steps

  1. 1

    Check PHP and whether wp already exists

    Where: SSH session to the web server, or Terminal on macOS/Linux

    Run both commands. If wp --info already prints WP-CLI details, WP-CLI is installed and you can stop here.

    php --version
    wp --info
    You should see: PHP reports version 7.2.24 or later. wp --info either prints WP-CLI details or "command not found".
  2. 2

    Download wp-cli.phar

    Where: The same terminal, in your home directory

    Download 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.phar
    You should see: curl shows a progress bar and wp-cli.phar is saved in your home directory.
  3. 3

    Optional: check the download is genuine

    Where: The same terminal

    Download 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.sha512
    You should see: The two hash values match exactly.
  4. 4

    Test that the Phar runs

    Where: The same terminal

    Run the file with PHP before installing it.

    php wp-cli.phar --info
    You should see: Output listing OS, Shell, PHP binary, PHP version, php.ini used and WP-CLI version.
  5. 5

    Make it executable and move it onto your PATH

    Where: The same terminal

    Make the file executable and move it to /usr/local/bin/wp so you can type wp from anywhere. Enter your password if sudo asks.

    chmod +x wp-cli.phar
    sudo mv wp-cli.phar /usr/local/bin/wp
    You should see: No output. The commands return to the prompt.
  6. 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-cli
    You should see: Homebrew installs wp-cli and the wp command is available.
  7. 7

    Windows: install PHP and create wp.bat

    Where: Windows PC, File Explorer and Command Prompt

    Install PHP and add it to your PATH. Create the folder C:\wp-cli and download wp-cli.phar into it from the URL above. In that folder create a text file named wp.bat containing the two lines below, then add the folder to your PATH with setx and open a new Command Prompt. The handbook notes wp.bat does not work in Git Bash; there you need an extensionless wp script 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. 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 root

    Change to the WordPress folder and check the site's home URL.

    cd /var/www/contoso.com/public_html
    wp option get home
    You should see: The site address is printed, for example https://contoso.com.
From experience

Expert tips

Skip plugins and themes to get past fatal errors

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.

Add --debug when something fails silently

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.

Check which PHP WP-CLI uses

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.

Use aliases for old and new servers

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.

Check it worked

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 home prints the site address.

Undo

How to reverse it

Rollback:

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.

Troubleshooting

Errors you might see

wp: command not found

Cause: 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.php

Cause: The file is saved with the wrong encoding.

Fix: Save wp-config.php as UTF-8 without BOM.

PHP Fatal error from wp-config.php

Cause: 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 hangs

Cause: Outbound connections to GitHub are blocked.

Fix: Allow outbound connections to GitHub on port 443.

FAQ

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.

Sources

Official sources

Vendors change menus and requirements. Confirm on the source before you rely on a detail. Last checked 4 Nov 2026.