Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WP Config Create is broken with 2.9.0 if socks MySQL connectivity is being used #169

Closed
aonsyed opened this issue Oct 26, 2023 · 5 comments

Comments

@aonsyed
Copy link

aonsyed commented Oct 26, 2023

Bug Report

Describe the current, buggy behavior

Since 2.9.0 last night, wp config create doesn't work if --dbhost=localhost:/var/run/mysqld/mysqld.sock is used, there is no issues with with the sock or configuration and everything works correctly if the config is manually created, only the create command is not working

Describe how other contributors can replicate this bug

Make sure that your database server is set to listen to socks and TCP port. Run something like this

/usr/local/bin/wp config create --dbname=dbname --dbuser=dbuser --dbpass=somevalue --dbprefix=wp_ --url=site.com --dbhost=localhost:/var/run/mysqld/mysqld.sock --allow-root --skip-themes --skip-packages --skip-plugins --path=/var/www/site.com/htdocs

And it will give you this error and there won't be a file

Error: Database connection error (2002) Connection refused

Describe what you would expect as the correct outcome

However if you run this

/usr/local/bin/wp config create --dbname=dbname --dbuser=dbuser --dbpass=somevalue --dbprefix=wp_ --url=site.com --dbhost=localhost --allow-root --skip-themes --skip-packages --skip-plugins --path=/var/www/site.com/htdocs

If will show you success message and fix config file will be created

Let us know what environment you are running this on

Tested this on Ubuntu 18, 20, 22 with multiple versions of Percona and mariaDB, wp --info remains identical

Provide a possible solution

Rolling back to 2.8.1

Provide additional context/Screenshots

N/A

If applicable, add screenshots to help explain (you can just drag&drop images into the Github issue).

@swissspidy
Copy link
Member

Thanks for your report!

This might be related to #158

In the meantime, have you tried running wp config create with the --skip-check flag to skip the database connection check?

@aonsyed
Copy link
Author

aonsyed commented Oct 30, 2023

Hi

The connection test can be modified as this

$mysql = mysqli_init();
mysqli_report(MYSQLI_REPORT_STRICT);

try {
    if (file_exists($assoc_args['dbhost'])) {
        // If dbhost is a path to a socket
        mysqli_real_connect($mysql, null, $assoc_args['dbuser'], $assoc_args['dbpass'], null, null, $assoc_args['dbhost']);
    } else {
        // If dbhost is a hostname or IP address
        mysqli_real_connect($mysql, $assoc_args['dbhost'], $assoc_args['dbuser'], $assoc_args['dbpass']);
    }
} catch (mysqli_sql_exception $exception) {
    WP_CLI::error('Database connection error (' . $exception->getCode() . ') ' . $exception->getMessage());
}

@danielbachhuber
Copy link
Member

@aonsyed Up for submitting a pull request with your suggested changes?

Here is some guidance on our pull request best practices.

@wojtekn
Copy link
Contributor

wojtekn commented Nov 10, 2023

@danielbachhuber I'm going to work on this.

@schlessera
Copy link
Member

Fixed via #171

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants