-
Notifications
You must be signed in to change notification settings - Fork 1k
WP-CLI command fails on WSL2 using phpenv with PHP 8.0.7 #5540
Description
Bug Report
Describe the current, buggy behavior
On my WSL2 I have a local setup (I'm using valet-wsl package to handle my websites), and for php version handling I'm using phpenv. I've installed PHP 8.0.7 and I'm using that as a global version, but my system is on PHP 7.4.3.
The mysql version is mysql Ver 8.0.25-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
The host system version is Ubuntu 20.04.
When trying to run any of the commands that have to connect to the database (either wp db, or wp theme activate, or similar) I get an error
PHP Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /home/dzoljom/Sites/Personal/my-wordpress/wp-includes/wp-db.php on line 1653The debug error looks like this:
wp theme activate project-test-bp --debug
Debug (bootstrap): Loading packages from: /home/dzoljom/.wp-cli/packages/vendor/autoload.php (0.007s)
Debug (bootstrap): Loading detected autoloader: /home/dzoljom/.wp-cli/packages/vendor/autoload.php (0.007s)
Debug (commandfactory): No doc comment for profile. (0.009s)
Debug (commands): Adding command: profile (0.01s)
Debug (bootstrap): Fallback autoloader paths: phar://wp-cli.phar/vendor/autoload.php (0.01s)
Debug (bootstrap): Loading detected autoloader: phar://wp-cli.phar/vendor/autoload.php (0.01s)
Debug (commands): Adding command: cache (0.012s)
Debug (commands): Adding command: transient (0.012s)
Debug (commands): Adding command: comment (0.014s)
Debug (commands): Adding command: meta in comment Namespace (0.014s)
Debug (commands): Adding command: menu (0.015s)
Debug (commands): Adding command: item in menu Namespace (0.016s)
Debug (commands): Adding command: location in menu Namespace (0.016s)
Debug (commands): Deferring command: network meta (0.016s)
Debug (commands): Adding command: option (0.017s)
Debug (commands): Adding command: post (0.018s)
Debug (commands): Adding command: meta in post Namespace (0.019s)
Debug (commands): Adding command: term in post Namespace (0.019s)
Debug (commands): Adding command: post-type (0.02s)
Debug (commands): Adding command: site (0.021s)
Debug (commands): Adding command: meta in site Namespace (0.022s)
Debug (commands): Adding command: option in site Namespace (0.022s)
Debug (commands): Adding command: taxonomy (0.023s)
Debug (commands): Adding command: term (0.024s)
Debug (commands): Adding command: meta in term Namespace (0.024s)
Debug (commands): Adding command: user (0.026s)
Debug (commands): Adding command: meta in user Namespace (0.027s)
Debug (commands): Adding command: session in user Namespace (0.027s)
Debug (commands): Adding command: term in user Namespace (0.027s)
Debug (commands): Adding command: network (0.027s)
Debug (hooks): Processing hook "after_add_command:network" with 1 callbacks (0.027s)
Debug (hooks): On hook "after_add_command:network": Closure in file phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/class-wp-cli.php at line 644 (0.028s)
Debug (commands): Adding command: meta in network Namespace (0.028s)
Debug (commands): Adding command: plugin (0.031s)
Debug (commands): Adding command: auto-updates in plugin Namespace (0.031s)
Debug (commands): Adding command: theme (0.033s)
Debug (commands): Adding command: auto-updates in theme Namespace (0.033s)
Debug (commands): Adding command: mod in theme Namespace (0.034s)
Debug (commands): Adding command: db (0.037s)
Debug (commands): Adding command: scaffold (0.04s)
Debug (commands): Adding command: export (0.04s)
Debug (commands): Adding command: core (0.04s)
Debug (commands): Adding command: verify-checksums in core Namespace (0.041s)
Debug (commands): Adding command: verify-checksums in plugin Namespace (0.041s)
Debug (commands): Adding command: import (0.042s)
Debug (commands): Adding command: media (0.044s)
Debug (commands): Adding command: package (0.046s)
Debug (commands): Adding command: config (0.047s)
Debug (commands): Adding command: core (0.049s)
Debug (commands): Adding command: cron (0.05s)
Debug (commands): Adding command: event in cron Namespace (0.05s)
Debug (commands): Adding command: schedule in cron Namespace (0.051s)
Debug (commands): Adding command: embed (0.051s)
Debug (commands): Adding command: fetch in embed Namespace (0.051s)
Debug (commands): Adding command: provider in embed Namespace (0.052s)
Debug (commands): Adding command: handler in embed Namespace (0.052s)
Debug (commands): Adding command: cache in embed Namespace (0.053s)
Debug (commands): Adding command: eval (0.053s)
Debug (commands): Adding command: eval-file (0.053s)
Debug (commands): Adding command: i18n (0.053s)
Debug (commands): Adding command: make-pot in i18n Namespace (0.054s)
Debug (commands): Adding command: make-json in i18n Namespace (0.055s)
Debug (commands): Adding command: make-mo in i18n Namespace (0.055s)
Debug (commands): Deferring command: language core (0.056s)
Debug (commands): Deferring command: language plugin (0.056s)
Debug (commands): Deferring command: language theme (0.056s)
Debug (hooks): Immediately invoking on passed hook "after_add_command:site": Closure in file phar:///usr/local/bin/wp/vendor/wp-cli/language-command/language-command.php at line 39 (0.056s)
Debug (commands): Adding command: switch-language in site Namespace (0.056s)
Debug (commands): Adding command: language (0.057s)
Debug (hooks): Processing hook "after_add_command:language" with 3 callbacks (0.057s)
Debug (hooks): On hook "after_add_command:language": Closure in file phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/class-wp-cli.php at line 644 (0.057s)
Debug (commands): Adding command: core in language Namespace (0.057s)
Debug (hooks): On hook "after_add_command:language": Closure in file phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/class-wp-cli.php at line 644 (0.057s)
Debug (commands): Adding command: plugin in language Namespace (0.057s)
Debug (hooks): On hook "after_add_command:language": Closure in file phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/class-wp-cli.php at line 644 (0.058s)
Debug (commands): Adding command: theme in language Namespace (0.058s)
Debug (commands): Adding command: maintenance-mode (0.058s)
Debug (commands): Adding command: rewrite (0.059s)
Debug (commands): Adding command: rewrite (0.059s)
Debug (commands): Adding command: cap (0.06s)
Debug (commands): Adding command: role (0.06s)
Debug (commands): Adding command: search-replace (0.062s)
Debug (commands): Adding command: server (0.062s)
Debug (commands): Adding command: shell (0.063s)
Debug (commands): Adding command: super-admin (0.063s)
Debug (commands): Adding command: widget (0.064s)
Debug (commands): Adding command: sidebar (0.064s)
Debug (bootstrap): Adding framework command: phar://wp-cli.phar/vendor/wp-cli/wp-cli/php/commands/cli.php (0.064s)
Debug (commands): Adding command: cli (0.066s)
Debug (commands): Adding command: cache in cli Namespace (0.066s)
Debug (commands): Adding command: alias in cli Namespace (0.066s)
Debug (bootstrap): Adding framework command: phar://wp-cli.phar/vendor/wp-cli/wp-cli/php/commands/help.php (0.067s)
Debug (commands): Adding command: help (0.067s)
Debug (bootstrap): No readable global config found (0.067s)
Debug (bootstrap): No project config found (0.067s)
Debug (bootstrap): argv: /usr/local/bin/wp theme activate project-test-bp --debug (0.067s)
Debug (bootstrap): ABSPATH defined: /home/dzoljom/Sites/Personal/my-wordpress/ (0.068s)
Debug (bootstrap): Begin WordPress load (0.068s)
Debug (bootstrap): wp-config.php path: /home/dzoljom/Sites/Personal/my-wordpress/wp-config.php (0.068s)
PHP Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /home/dzoljom/Sites/Personal/my-wordpress/wp-includes/wp-db.php on line 1653
PHP Stack trace:
PHP 1. {main}() /usr/local/bin/wp:0
PHP 2. include() /usr/local/bin/wp:4
PHP 3. include() phar:///usr/local/bin/wp/php/boot-phar.php:11
PHP 4. WP_CLI\bootstrap() phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php:27
PHP 5. WP_CLI\Bootstrap\LaunchRunner->process($state = class WP_CLI\Bootstrap\BootstrapState { private $state = [] }) phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php:77
PHP 6. WP_CLI\Runner->start() phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php:23
PHP 7. WP_CLI\Runner->load_wordpress() phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:1192
PHP 8. require() phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:1271
PHP 9. require_wp_db() /home/dzoljom/Sites/Personal/my-wordpress/wp-settings.php:124
PHP 10. wpdb->__construct($dbuser = 'root', $dbpassword = '', $dbname = 'wordpress-test', $dbhost = 'localhost') /home/dzoljom/Sites/Personal/my-wordpress/wp-includes/load.php:545
PHP 11. wpdb->db_connect($allow_bail = *uninitialized*) /home/dzoljom/Sites/Personal/my-wordpress/wp-includes/wp-db.php:632
PHP 12. mysqli_real_connect($mysql = class mysqli { public $client_info = 'mysqlnd 8.0.7'; public $client_version = 80007; public $connect_errno = 2002; public $connect_error = 'No such file or directory'; public $errno = 2002; public $error = 'No such file or directory' }, $hostname = 'localhost', $username = 'root', $password = '', $database = NULL, $port = NULL, $socket = NULL, $flags = 0) /home/dzoljom/Sites/Personal/my-wordpress/wp-includes/wp-db.php:1653
Error: `No such file or directory`
Error establishing a database connection
This either means that the username and password information in your `wp-config.php` file is incorrect or we can’t contact the database server at `localhost`. This could mean your host’s database server is down.
Are you sure you have the correct username and password?
Are you sure you have typed the correct hostname?
Are you sure the database server is running?
If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums. `No such file or directoryNow, when I switch to PHP 7.4, all is well and working.
The WP will run just fine under PHP 8.0.7 (no errors so far). So I'm not sure why this is failing (especially if the WP instance is running just fine).
Also, not sure if this is just a PHP version, or phpenv related.
Describe how other contributors can replicate this bug
- Have WSL2 installed (Ubuntu 20.04)
- Set up a site using
valet-wsl, Mysql 8 and phpenv - Set the version of PHP to 8.0.7
- Install the WP and confirm it works in the browser
- Try to run any command that uses the database
Describe what you expect as the correct outcome
I expect the command to work like it does on PHP 7.4
Let us know what environment you are running this on
OS: Linux 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64
Shell: /usr/bin/zsh
PHP binary: /home/dzoljom/.phpenv/versions/8.0.7/bin/php
PHP version: 8.0.7
php.ini used: /home/dzoljom/.phpenv/versions/8.0.7/etc/php.ini
MySQL binary: /usr/bin/mysql
MySQL version: mysql Ver 8.0.25-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
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: /home/dzoljom/Sites/Personal/my-wordpress/wp-content/themes/project-test-bp
WP-CLI packages dir: /home/dzoljom/.wp-cli/packages/
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.5.0
Provide a possible solution
Honestly not sure what the issue could be, but I am willing to help anybody to debug this so that they don't have to create the setup themselves since it is a bit specific (WSL2 + phpenv).