Using WordPress WP-CLI in windows

I was setting up my wordpress development environment in windows today. I wanted to have php unit tests for the plugin I have been developing for a few days, and I ran into an article which says wp-cli.phar cannot be used in windows! The article was about using PHPUnit to write wordpress plugin unit tests.

Okay, PHAR is just a php application in an archived folder. If it’s made as executable, it should run on windows, too. So, I figured out how to install wp-cli in windows.

So, I tried this:

  1. Create a directory for PHP binaries; e.g., C:\bin
  2. Append ;C:\bin to your PATH environment variable (related help)
  3. Download wp-cli.phar and save the file as C:\bin\wp-cli.phar
  4. Open a command line (e.g., press Windows+R » type cmd » ENTER)
  5. Create a wrapping batch script (results in C:\bin\wp.cmd):
    C:\Users\username> cd C:\bin
    C:\bin> echo @php "%~dp0wp-cli.phar" %* > wp.cmd
    C:\bin> exit
  6. Open a new command line and confirm that you can execute WP CLI from any path:
    C:\Users\username> wp --info

And it WORKS.

The idea totally came from the steps of installing PHPUnit in windows. Nothing special, just a curiosity led to the solution.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s