WP-CLI Installation Guide

WP-CLI is a command-line interface for WordPress. It allows you to manage your WordPress website through the command line, which can be faster and more efficient than using the WordPress admin interface. This guide will provide you with step-by-step instructions on how to install WP-CLI on both Linux and Windows environments.

Prerequisites:

  • PHP 5.4 or later
  • WordPress 3.7 or later
  • SSH access to your server for Linux installations
  • Administrator privileges for Windows installations

Installation on Linux

  1. Download WP-CLI:

Open a terminal window and download the WP-CLI installation script using wget or curl. Use the following command to download the WP-CLI Phar file:

Bash
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
  1. Make WP-CLI Executable:

You will need to make the downloaded Phar file executable. You can do this with the following command:

Bash
chmod +x wp-cli.phar
  1. Move WP-CLI to Bin Directory:

For easy access, you will want to move the executable to your PATH. The /usr/local/bin directory is a common location. Use the following command to move the file:

Bash
sudo mv wp-cli.phar /usr/local/bin/wp
  1. Verify WP-CLI Installation:

Finally, check that WP-CLI has been installed correctly by displaying the version number. You can do this with the following command:

Bash
wp --info

Installation on Windows

  1. Download WP-CLI:

Visit the WP-CLI’s Github page and download the latest Phar file. You can download the file directly from this URL:

Bash
https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
  1. Download and Install Cygwin:

Since WP-CLI is a command line tool, and Windows does not have a built-in suitable terminal, you will need to download and install Cygwin. You can download it from the official site:

Bash
https://www.cygwin.com/

During installation, ensure that you install the curl, php, php-curl, php-mbstring, openssl, and openssh packages.

  1. Move WP-CLI to the Cygwin Directory:

Move the wp-cli.phar file to your Cygwin home directory, usually C:\cygwin64\home\Your_User.

  1. Make WP-CLI Executable:

Open Cygwin terminal and navigate to your home directory using cd ~. Then, make the downloaded Phar file executable with the following command:

Bash
chmod +x wp-cli.phar
  1. Move WP-CLI to Bin Directory:

For easy access, you will want to move the executable to your PATH. The /usr/bin directory within Cygwin is a common location. Use the following command to move the file:

Bash
mv wp-cli.phar /usr/bin/wp
  1. Verify WP-CLI Installation:

Finally, check that WP-CLI has been installed correctly by displaying the version number. You can do this with the following command:

Bash
wp --info

Conclusion

Now that WP-CLI is installed, you can start using it to manage your WordPress site from the command line. If you need help getting started with WP-CLI, the official WP-CLI website provides a comprehensive guide and detailed command reference.

Updated on May 28, 2023