I finally managed to scrape together enough information from disparate sources to figure out how to fix this, because - as I'm increasingly finding with anything related to Wordpress development - the documentation is so woefully inadequate.
The fact that it took so much research and hacking together on my part just to get an official command-line utility working on a platform that it claims to support is ridiculous, and my estimation of the Wordpress project and the Automattic team has dropped massively over the last few weeks for such reasons.
What follows in this answer adapts information from aefxx's answer here and leymannx's answer to this question.
As far I can tell, the issue here is that php.exe
- the PHP binary included with XAMPP, WAMP and similar local servers - is a Windows binary that only understands paths in Windows format. The solution, as coded by aefxx in his answer, is to use a wrapper script that checks for Unix-style paths passed to the PHP binary and converts them into Windows paths that it can understand.
Note that because this solution is implemented as a wrapper to the PHP binary itself, it should work to solve this issue for any PHP program running under Cygwin, not just WP-CLI.
How to get WP-CLI working with Cygwin
Remember to replace any paths below with your own.
Once you've downloaded the wp-cli.phar
file and made it executable as detailed in the documentation, move it to where you want to install it - /usr/local/bin
tends to be the convention for user-installed binaries on Linux, or inside of XAMPP's PHP server root if you're using XAMPP - and rename it to something easier to type, like wp
:
mv wp-cli.phar /cygdrive/c/XAMPP/php/wp
Then, navigate to the new install directory and create a wrapper file called php
:
cd /cygdrive/c/XAMPP/php/wp &&
touch php &&
chmod +x ./php
Open the file in a text editor and paste the following into it, replacing the path to the PHP executable with your own:
#!/bin/bash
php="/cygdrive/c/XAMPP/php/php.exe"
for ((n=1; n <= $#; n++)); do
if [ -e "${!n}" ]; then
# Converts Unix style paths to Windows equivalents
path="$(cygpath --mixed ${!n} | xargs)"
case 1 in
$(( n == 1 )) )
set -- "$path" "${@:$(($n+1))}";;
$(( n < $# )) )
set -- "${@:1:$((n-1))}" "$path" ${@:$((n+1)):$#};;
*)
set -- "${@:1:$(($#-1))}" "$path";;
esac
fi
done
"$php" "$@"
Finally, run wp
to confirm that WP-CLI - and any other PHP tools requiring a Cygwin wrapper - is now working on Cygwin.