If you are a developer and passionate to work on CLI commands instead of a web browser then in this article I’m going to share with you how to install WP CLI (Command Line Interface).

Table of Content

Overview Overview

WP CLI (WordPressWordPress WordPress (WordPress.org) is a content management system (CMS) based on PHP and MySQL that is usually used with the MySQL or MariaDB database servers but can also use the SQLite database engine. Command Line Interface) is the command-line tool interface for WordPress. We can do all the things in the command line which we do through the WordPress backend.

E.g. installing plugin, switching theme, creating new users, updating WordPress, setup multisite installations and much more.

WP CLI Exist? WP CLI Exist?

We can install the WP CLI on any system (Windows, Linux, Unix etc).

We can also install WP CLI on the live server like Google Cloud Console.

Some, Hosting providers already have the WP CLI setup. So, Before installing the WP CLI just check the WP CLI is installed on your server or system, Just open your terminal and type below command:

wp

Step 1: Create a Directory Step 1: Create a Directory

We can set up the WP CLI anywhere in our system. In this example, I’m going to set up on my C drive.

So, Just goto C drive and create a new directory wp-cli like:

c:\wp-cli

Step 2: Download Phar File Step 2: Download Phar File

Download the Phar file of WP CLI which contains all the executable files.

Click and download the wp-cli.phar.

Or

Go to https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar and download it.

Step 3: Copy & Paste Phar file Step 3: Copy & Paste Phar file

Now, Copy the wp-cli.phar file and paste into your newly created wp-cli directory.

That’s C:\wp-cli\

Step 4: Create wp.bat Step 4: Create wp.bat

Now, Create the empty wp.bat file in C:\wp-cli\ and then copy and paste the below code in it.

@ECHO OFF
php "C:\wp-cli\wp-cli.phar" %*

Or

Download the wp.bat file from https://gist.github.com/848b5a9f21f27239600cf08693a0bedb

Step 5: Setup Environment Path Step 5: Setup Environment Path

We need to set up the system environment path of our WP CLI setup (c:\wp-cli\).

Done!


Open Command Prompt and type command wp and press Enter. It’ll show you the like the below screenshot.


Not work on Git Bash? Not work on Git Bash?

Create another file wp without any extension into the C:\wp-cli\ directory and paste below code:

#!/usr/bin/env sh
 
dir=$(d=${0%[/\\]*}; cd "$d"; pwd)
 
# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
   # Cygwin paths start with /cygdrive/ which will break windows PHP,
   # so we need to translate the dir path to windows format. However
   # we could be using cygwin PHP which does not require this, so we
   # test if the path to PHP starts with /cygdrive/ rather than /usr/bin
   if [[ $(which php) == /cygdrive/* ]]; then
       dir=$(cygpath -m $dir);
   fi
fi
 
dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/wp-cli.phar" "$@"

Great!

Now open git bash and type command wp Eg.

Source https://deluxeblogtips.com/install-wp-cli-windows/

Conclusion Conclusion

It is very easy to work on a terminal or command prompt with the help of WP CLI. Let’s try it and add your opinions in the comment.

Leave a Reply

Your email address will not be published. Required fields are marked *