Error on Windows 11 with WP CLI 2.6 and PHP 8.1.6
symisz opened this issue · 8 comments
I'm using PHP 8.1.6 with wp cli 2.6 and get the following error:
It worked fine before with wp cli 2.4 and an older PHP version.
Here is a section of the command I used. (command is cut here for privacy reasons)
wp config create --dbhost="127.0.0.1" --dbuser="....."
'"mysql --no-defaults --execute="' is not recognized as an internal or external command,
operable program or batch file.
Thanks for the report, @symisz !
Are you able to wp cli update --nightly
and see if the error reproduces with the latest nightly?
Also, can you share the output of wp cli info
?
Thanks for your reply @danielbachhuber !
I was able to run wp cli update --nightly
this time around, wasn't successful before however.
And I get the same error message on the current nightly build:
1/9 --dbname=: dev3
2/9 [--dbpass=]:
wp config create --dbhost="..." --dbuser="..." --dbcharset="utf8mb4" --dbcollate="utf8mb4_unicode_ci" --force --dbname="dev3" --dbprefix="wp_"
'"mysql --no-defaults --execute="' is not recognized as an internal or external command,
operable program or batch file.
wp cli info output:
OS: Windows NT 10.0 build 22622 (Windows 11) AMD64
Shell: C:\WINDOWS\system32\cmd.exe
PHP binary: C:\xampp\php\php.exe
PHP version: 8.1.6
php.ini used: C:\xampp\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: G:\htdocs\dev3
WP-CLI packages dir:
WP-CLI global config: C:\Users\USERNAME/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.7.0-alpha-38dab66
While this testing has been done on PHP 8.1.6
I was in the midst of reverting back to PHP 7.4, as I read some other users have rumored it to be more stable with WP CLI on Windows.
@symisz From your wp cli info
, it does appear WP-CLI doesn't know how to find your mysql
binary.
Here's how it attempts to do so: https://github.com/wp-cli/wp-cli/blob/b179c7a096b5de51a002f91a7a9ad1e0183678b5/php/utils.php#L1719-L1738
Does WordPress itself run on PHP 8.1.6? Where does your mysql
binary live on your system?
@danielbachhuber WordPress seems to run fine on PHP 8.1.6.
I'm using a package installer called Xampp and it installs the mysql binary to C:\xampp\mysql\bin
On my Windows system I have manually added the environment variable and in particular for mysql, points to C:\xampp\mysql\bin\
and the wp config create
command worked fine, prior to using PHP 8.1.6 and WP CLI 2.6+.
I've checked the environment variable again, and no new changes where made in this regard.
It worked fine when using Xampp, which might been shipped with PHP 7.2. and back then I used WP CLI 2.4.0.
It seems the script only targets the UNIX path to the mysql binary: /usr/bin/env
https://github.com/wp-cli/wp-cli/blob/b179c7a096b5de51a002f91a7a9ad1e0183678b5/php/utils.php#L1719-L1738
I'm going to revert to PHP 7.4 or 7.2 and check the wp cli info
and test the command wp config create
I've since reverted back to PHP 7.4 and did a test with 2.4.0 and the latest alpha, which both have no problem executing the command: wp config create
wp cli info on 2.4
OS: Windows NT 10.0 build 22622 (Windows 10) AMD64
Shell: C:\WINDOWS\system32\cmd.exe
PHP binary: C:\xampp\php\php.exe
PHP version: 7.4.29
php.ini used: C:\xampp\php\php.ini
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: G:\htdocs\dev3
WP-CLI packages dir:
WP-CLI global config: C:\Users\USERNAME/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.4.0
Success: Generated 'wp-config.php' file.
wp cli info on latest nightly 2.7.0-alpha-38dab66
OS: Windows NT 10.0 build 22622 (Windows 10) AMD64
Shell: C:\WINDOWS\system32\cmd.exe
PHP binary: C:\xampp\php\php.exe
PHP version: 7.4.29
php.ini used: C:\xampp\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: G:\htdocs\dev3
WP-CLI packages dir:
WP-CLI global config: C:\Users\USERNAME/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.7.0-alpha-38dab66
Success: Generated 'wp-config.php' file.
There is an absent of the mentioning of the mysql binary in both the output.
The Xampp package differences:
Includes: Apache 2.4.53, MariaDB 10.4.24, PHP 7.4.29
Includes: Apache 2.4.53, MariaDB 10.4.24, PHP 8.1.6
@symisz Interesting! Can you share the output for wp cli info
against WP-CLI v2.5.0/2.6.0 as well?
Here are some changes to WP_CLI\Utils\run_mysql_command()
in the last few releases:
There was also the introduction of WP_CLI\Utils\get_mysql_binary_path()
: wp-cli/wp-cli#5386
It seems like the most likely candidate is that /usr/bin/env mysql
exists in your old environment, and doesn't exist in your new environment.
@danielbachhuber I'm getting the same result on PHP 7.4.29
OS: Windows NT 10.0 build 22622 (Windows 10) AMD64
Shell: C:\WINDOWS\system32\cmd.exe
PHP binary: C:\xampp\php\php.exe
PHP version: 7.4.29
php.ini used: C:\xampp\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: G:\htdocs\dev3
WP-CLI packages dir:
WP-CLI global config: C:\Users\USERNAME/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.5.0
Success: Generated 'wp-config.php' file.
OS: Windows NT 10.0 build 22622 (Windows 10) AMD64
Shell: C:\WINDOWS\system32\cmd.exe
PHP binary: C:\xampp\php\php.exe
PHP version: 7.4.29
php.ini used: C:\xampp\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: G:\htdocs\dev3
WP-CLI packages dir:
WP-CLI global config: C:\Users\USERNAME/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.6.0
Success: Generated 'wp-config.php' file.
@symisz As it turns out, there was an existing issue for this! wp-cli/wp-cli#5521
I've landed a couple of changes in the nightly build. Can you run wp cli update --nightly
, and then see if the issue still exists?
@danielbachhuber Thanks for this update! Happily to confirm that it works on PHP 7.4 as well on the latest 8.10, as @mlipe-nxs has mentioned in his post.
Very much appreciated by the effort by you and others that have put into this!
The MySQL binary/version info are not being retrieved to be displayed as seen here:
here is my wp cli info output:
OS: Windows NT 10.0 build 22623 (Windows 11) AMD64
Shell: C:\WINDOWS\system32\cmd.exe
PHP binary: C:\xampp\php\php.exe
PHP version: 8.1.10
php.ini used: C:\xampp\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: G:\htdocs\dev3
WP-CLI packages dir:
WP-CLI cache dir: C:\Users\USERNAME/.wp-cli/cache
WP-CLI global config: C:\Users\USERNAME/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.8.0-alpha-bd378d0