Wp is not recognized as an internal or external command, operable program or batch file

What is WP-CLI?

WP-CLI is a command line tool to manage operations of a WordPress project. It can manage posts, categories, users, search-replace in the DB, change passwords and more!

WP-CLI is very extensible/useful and we can do many more things quickly.

Prerequisite: The minimum PHP version 5.4 is required to run WP-CLI v2.0.0 so upgrade you PHP version if not match with minimum requirement.

Let discuss in detail but installation:

You just need to follow below steps and it will be ready in few minutes.

Step 1: check pre configurations PHP

Open the CMD (win+R-> type cmd) and type php -v command to check PHP variable in configured or not.

Just verify this above because if you have installed PHP but not configured environment variable in system then it will show below error

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

(for Xampp):

XAMPP does not provide in-build console to run php commands, so, you have to add to environment variables under Control Panel\System and Security\System > Advanced system settings > Environment Variables like below screen


  • Select "Path" from "System Variables" and click on "Edit" button
  • Now set path where php.exe file is located - For XAMPP, it is installed in to C: drive then Path is "C:\xampp\php"
  • Paste this above directory path at end of the path and sperate with semicolon
  • Click Ok and Apply.

(for wamp):

Wamp server have different directory structure so PHP is available under c:\wamp\bin\php\php.#.#.# (here last directory based on PHP version you have running on)

Copy this path

Now you have to add to environment variables under Control Panel\System and Security\System > Advanced system settings > Environment Variables

  • Select "Path" from "System Variables" and click on "Edit" button
  • Paste you copied PHP directory path at end of the path and sperate with semicolon
  • Click Ok and Apply.

Step2: Install wp-cli for windows

  • Download wp-cli.phar manually and save it to a folder, for example c:\wp-cli
  • Create a file named wp.bat in c:\wp-cli with the following contents:

@ECHO OFF
php "c:/wp-cli/wp-cli.phar" %*

Step 3: Set environment variable for wp-cli

Add c:\wp-cli to your environment path 

Go to Control Panel\System and Security\System > Advanced system settings > Environment Variables

  • Select "Path" from "System Variables" and click on "Edit" button
  • Paste you copied wp-cli directory path at end of the path and sperate with semicolon
  • Click Ok and Apply.

Step 4: Confirm after setup all

In order to check that everything is working properly, you can run the info command:

Open the CMD (win+R-> type cmd) and type wp --info command to check WP-CLI is now available or not.

You can see similar output like below screen

 


Step 5: Done

That’s it. Enjoy!

It will save you from lot of clicks, page load time.


  • Tweet
  • Share
  • Share
  • Share
  • Share

Sign up here with your email

Hi,
I have a problem.
'"mysql --no-defaults --execute="' is not recognized as an internal or external command,
operable program or batch file.

OS: Win10
Lastest version wp-cli

CMD Window:
`c:\wamp64\www\wordpress_cli>mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.21 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> exit
Bye

c:\wamp64\www\wordpress_cli>php .\wp-cli.phar config create --dbname=xx --dbuser=root
'"mysql --no-defaults --execute="' is not recognized as an internal or external command,
operable program or batch file.

c:\wamp64\www\wordpress_cli>`

I'm seeing the same behavior, Using WP-CLI on XAMPP. Both php and mysql dirs are on PATH.

I'm also having the same issue.
none of the wp db * commands are working .

e.g. wp db check

'"mysqlcheck --no-defaults "wordpress" --check --host="localhost" --user="root" --default-character-set="utf8""' is not recognized as an internal or external command, operable program or batch file.

OS: windows 10
PHP: 8.0.3
MySql: 5.7.31

same issue on windows 10 with xampp. mysql is in the paths both the current user and globally
any idea how to fix it?

Same issue on Windows 10 with Xampp.

I solved my problem by upgrading Windows to version Windows 10 Pro 21H1, build 19043.1237.

I am having this issue as well when I run the following command, I get the following output.

$ wp config create --dbname=myTestDb --dbuser=root --dbpass=rootbeer '"mysql --no-defaults --execute="' is not recognized as an internal or external command, operable program or batch file.

I have verfied that mysql is in my path with the following:

$ mysql --version C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe Ver 8.0.23 for Win64 on x86_64 (MySQL Community Server - GPL)

This is the output from command wp --info

$ wp --info OS: Windows NT 10.0 build 19043 (Windows 10) i586 Shell: C:\Program Files\Git\usr\bin\bash.exe PHP binary: C:\PHP\php.exe PHP version: 8.0.12 php.ini used: C:\PHP\php.ini MySQL binary: MySQL version: SQL modes: WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli WP-CLI vendor dir: phar://wp-cli.phar/vendor WP_CLI phar path: C:\Sites\markdurb.in\wordpress WP-CLI packages dir: WP-CLI global config: WP-CLI project config: WP-CLI version: 2.5.0

I have done this on (2) different machines running this same version of Windows, with the same result. I have tried multiple versions of MySQL 8.0.x and the two latest versions of PHP.

Any advice?

I am having this issue as well when I run the following command, I get the following output.

$ wp config create --dbname=myTestDb --dbuser=root --dbpass=rootbeer '"mysql --no-defaults --execute="' is not recognized as an internal or external command, operable program or batch file.

I have verfied that mysql is in my path with the following:

$ mysql --version C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe Ver 8.0.23 for Win64 on x86_64 (MySQL Community Server - GPL)

This is the output from command wp --info

$ wp --info OS: Windows NT 10.0 build 19043 (Windows 10) i586 Shell: C:\Program Files\Git\usr\bin\bash.exe PHP binary: C:\PHP\php.exe PHP version: 8.0.12 php.ini used: C:\PHP\php.ini MySQL binary: MySQL version: SQL modes: WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli WP-CLI vendor dir: phar://wp-cli.phar/vendor WP_CLI phar path: C:\Sites\markdurb.in\wordpress WP-CLI packages dir: WP-CLI global config: WP-CLI project config: WP-CLI version: 2.5.0

I have done this on (2) different machines running this same version of Windows, with the same result. I have tried multiple versions of MySQL 8.0.x and the two latest versions of PHP.

Any advice?

Downgraded to PHP 7.4.25 and error is no longer happening. Prior to downgrade, I commented out the following line in proc_open_compat in utils.php
$cmd = _proc_open_compat_win_env( $cmd, $env );
This also resolved the issue.

Hope this is helpful.

I am also facing same issue with my wp-cli. Anyone got solution on this?

I downgraded from PHP 8.1.1 to PHP 7.4.27 and it worked.

Same issue with Xampp + PHP v8.1.1. Both PHP and MySQL is in the PATH.

Same with me but below PHP 8x working fine but PHP 8x+ showing "'"mysql --no-defaults --execute="' is not recognized as an internal or external command, operable program or batch file." error

PHP 8.0.15 is also not compatible, switching to 7.4.x worked.

Would be nice if we didn't have to switch back for WP-CLI.

Looks like PHP 8+ has a Windows compat bug fix, which causes our workaround to break...

any news here? is this problem still unresolved?

Anyone managed to make this work with PHP 8.x?

We do a lot of CLI stuff with WordPress, and right now our only workaround on Windows is to manually specify the PHP version when running WP-CLI commands that need the database.

So for instance we might run this through GitBash (your paths will vary):

/c/DevTools/php/7.4/php /c/DevTools/wordpress/wp --version

Actually, we more often than not use Symfony's CLI to proxy commands because you can specify a PHP version in a specially named file, so our command is slightly shorter:

symfony php /c/DevTools/wordpress/wp --version

These commands could be aliased pretty easily, too.

This is all just workarounds, we haven't found a fix, but at least we can keep working.

Thanks for your input @cjhaas I will try this with PHP 8.x, with PHP 7.4 wp-cli still works.

Looks like PHP 8+ has a Windows compat bug fix, which causes our workaround to break...

Is there any chance to get this fixed @schlessera or what is required to move this issue forward? WP CLI defines support for PHP ^8.0 but it seems not really to work - at least on Windows. 🤔

@schlessera Hi! Maybe is there some solution to deal with this bug?

We have the same issue for other operations, e.g. remove of plugin:

C:\Users\Administrator>c:\php-8.0\php.exe -dsafe_mode=off -ddisplay_errors=on -dopen_basedir= -d max_execution_time=60 "C:\wp-cli.phar" "--path=C:\Inetpub\vhosts\abc.tld\httpdocs" --debug --no-color plugin uninstall akismet "--skip-plugins=akismet,hello,thanks_for_read" ... Debug (hooks): On hook "before_run_command": WP_CLI\Bootstrap\RegisterDeferredCommands->add_deferred_commands() (9.385s) Debug (bootstrap): Running command: plugin uninstall (9.387s) C:\Users\Administrator>echo %errorlevel% 1

Plugin files are not removed!

Environment: Windows, PHP 8.0, for example:

C:\Users\Administrator>c:\php-8.0\php.exe -dsafe_mode=off -ddisplay_errors=on -dopen_basedir= -d max_execution_time=60 "C:\wp-cli.phar" --info OS: Windows NT 10.0 build 14393 (Windows Server 2016) AMD64 Shell: C:\Windows\system32\cmd.exe PHP binary: c:\php-8.0\php.exe PHP version: 8.0.21 php.ini used: C:\Program Files (x86)\Plesk\Additional\PleskPHP80\php.ini MySQL binary: MySQL version: SQL modes: WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli WP-CLI vendor dir: phar://wp-cli.phar/vendor WP_CLI phar path: C:\Users\Administrator WP-CLI packages dir: WP-CLI global config: WP-CLI project config: WP-CLI version: 2.6.0

Once I comment out

// Need to encompass the whole command in double quotes - PHP bug //bugs.php.net/bug.php?id=49139 cmd = '"' . _proc_open_compat_win_env( $cmd, $env ) . '"';

at utils.php, plugin remove works perfectly.

Also, switch to PHP 7.4 helps.

Could you please fix compatibility of WP-CLI with PHP 8.0 and later on Windows?

How do I run a WordPress command line in Windows?

Installing WP-CLI in Windows.
Install Composer. Download and install the Composer . ... .
Install PHP. You probably have XAMPP already installed in your system that already installed the PHP environment. ... .
Begin install WP CLI. Once above set up are completed, download phar file. ... .
Set environment variable..

How do I install WordPress on terminal?

Once the database has been created, go to the SSH terminal and open the WordPress folder with cd command..
Install LAMP..
Install phpMyAdmin..
Download & Unzip WordPress..
Create a Database through phpMyAdmin..
Give special permission to the WordPress directory..
Install WordPress..

How do I run command line commands in WordPress?

phar file directly to access the WP-CLI tool. To make it available globally on the system, move it to your /usr/local/bin/ directory and rename it to wp . This ensures that you can access WP-CLI from any directory by entering the wp command at the start of a prompt: sudo mv wp-cli.

What is WP CLI Phar?

The WP-CLI is a tool that enables you to interact with your WordPress site directly by using commands in a text-based interface. It's also very comprehensive, featuring a wide variety of potential commands. Almost anything you can do on the back end of your site, you can do much faster using the WP-CLI.

zusammenhängende Posts

Toplist

Neuester Beitrag

Stichworte