(To skip all the drama and go directly to getting a WordPress site with WP CLI running in just a few steps, click here.)

Dramatic intro

I’ve been working with WordPress for quite a while now, both hobby and professional, and I’ve always held off using WP CLI, the command-line interface for doing things. Because all that can be done in our admin tool anyways, so why bother, right?

But, I did try a few times. And failed every single time. Why? Mostly because I’m a Windows user, and most of the guides, tutorials, tools, and everything else in tech world assumes you’re on a Mac (I tried that too for a year or so, and was very happy to go back to Windows).

WP CLI‘s page states as the first requirement: “UNIX-like environment (OS X, Linux, FreeBSD, Cygwin); limited support in Windows environment“. Well that’s just great.

Maybe install VVV, that will create a virtual machine with that important UNIX-like environment? That’s probably where my stupidity came in, cause I couldn’t get that to work properly either. I think. Maybe I did. Maybe it was just a bit too much for what I needed. Either way, I wasn’t happy for some reason, so I yelled “EVERYONE HATES DEVELOPERS WHO ARE ON WINDOWS!“, cried over some tacos, and dropped it again.

So recently, I decided to give it another go. This may or may not have to do with the fact that I’m using WP CLI at work now, so I thought it wouldn’t be a bad idea to have a local copy available where I could experiment a bit with it. After finding a simple (but good) Vagrant box and tweaking it a bit, I think I ended up with pretty simple way of having a basic WordPress site running in an environment that totally supports WP CLI, on Windows. Bonus: it should work just as well on a Mac.

Enough! How to get this running?!

Prerequisites first! Install VirtualBox, install Vagrant, and if you’re on Windows, get a copy of Putty.

All done? Let’s go.

  1. Download this simple Vagrant box and unzip it to any directory you like. Let’s say, /mywebsite/.
  2. Add the following entries to your hosts file:      wp-cli.local      phpmyadmin.wp-cli.local

    OPTIONAL: click here if you intend to use different IP or URLs

    If you enter a different IP address in the hosts file , make sure it matches the value in /mywebsite/vagrant/Vagrantfile (line 12).

    If you use different URLs, make sure they match the values on line 2 of /mywebsite/vagrant/config/wordpress.conf and /mywebsite/vagrant/config/phpmyadmin.conf, as well as line 134 of /mywebsite/vagrant/shellprovider.sh.

  3. Using your command line (Windows) or Terminal (Mac), go to /mywebsite/vagrant, type vagrant up and wait for 5-10 minutes while your virtual machine becomes self-aware is built and configured.

Ummmm….that’s pretty much it. You should now have a WordPress site running at http://wp-cli.local.

You can now SSH into the server (using putty.exe on Windows, or Terminal on Mac) by connecting to wp-cli.local (username/password: vagrant/vagrant).

Once in the server, type cd /var/www/html/wordpress and you can WP CLI all you want. I won’t get into all that here, but you can find all the handy commands and documentation at https://developer.wordpress.org/cli/commands/.

Final notes

  • Username and password for http://wp-cli.local is wp/wp.
  • This whole method is not super secure, since I’ve hard-coded some passwords. You can change that (before you run step 3 above) in /mywebsite/vagrant/shellprovider.sh, lines 121, 133 and 134.
  • Access phpMyAdmin with username root and no password.
  • To stop the virtual machine, enter vagrant halt in /mywebsite/vagrant.