wp-cli icon indicating copy to clipboard operation
wp-cli copied to clipboard

Add to Documentation - wp-cli for windows using gitbash

Open Craigeniah opened this issue 4 years ago • 2 comments

Hello,

I spent most of my day trying to troubleshoot why the wp-cli was not working correctly on my windows machine. As it turns out it was the git bash portion that was not allowing it to work. I use git bash as my command line tool of choice.

I think it would be helpful to many to add this detail to the documentation located here.

The solution I found from here: https://maheshwaghmare.com/setup-wp-cli-wordpress-command-line-interface-on-windows-operating-system/#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.

Craigeniah avatar Jun 24 '20 01:06 Craigeniah

Thanks, at least that makes wp-cli active in Git Bash. but it still throws fatal error "Call to undefined function mysql_connect()".

enrique71 avatar Apr 01 '21 19:04 enrique71

Sounds great! Feel free to submit a pull request against the documentation: https://github.com/wp-cli/handbook/blob/main/installing.md

danielbachhuber avatar Jul 21 '23 16:07 danielbachhuber