1

I have tried to install Wordpress CLI on my windows machine running windows 10. But for some reason everytime i try to run the

wp

Command it says

'sh' is not recognized as an internal or external command,operable program or batch file. 

I have tried multiple times to reinstall it and set it up from scratch with different guides but it just won't work.

This is what the bat file says

@ECHO OFF
SET BIN_TARGET=%~dp0/./wp-cli.phar
php "%BIN_TARGET%" %*

This is the environment variable i am using to point it to the bat file enter image description here

That is where the .phar file and my .bat file are located to run the CLI.

All help is appreciated

Regards

Jonas Bang

2
  • 1
    Where did the .bat come from? I'm surprised they gave you one if it then needs sh. But it looks you'll need a unix-like environment for your Windows e.g. Git bash or WSL2. Note however the homepage says "limited support in Windows environment"
    – Rup
    Sep 28 at 9:51
  • have you attempted the official windows install method at make.wordpress.org/cli/handbook/guides/installing/…? Note that WP CLI has limited compatibility on a Windows non-Unix environment. You would be better off with a containerised/virtual environment that provides Linux, such as WSL or perhaps even git bash
    – Tom J Nowell
    Sep 28 at 9:57
1

Currently i have several process running in my CI/CD with wp-cli and all works fine in windows and unix. In my experience this is your best option in windows:

#1 Add PHP to your Windows Path Variable

#2 Install, as @Rup suggests, Git-bash terminal.

#3 Execute an wp-cli command like that:

vendor/bin/wp cache flush --path=public/wp-cms/wp-core

*This code consider you are using wp-cli managed with composer, and the files are locatted at vendor folder, otherwise you can replace vendor/bin/wp with wp

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.