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-CLI fails to connect when wp-config.php has database environment variables #3729

Closed
bgeihsgt opened this issue Jan 12, 2017 · 7 comments · Fixed by #3730
Closed

WP-CLI fails to connect when wp-config.php has database environment variables #3729

bgeihsgt opened this issue Jan 12, 2017 · 7 comments · Fixed by #3730

Comments

@bgeihsgt
Copy link

This is similar to #2365 which I don't think got properly resolved.

I want my wp-config.php to be stateless so can deploy it to any environment (in this case, I'm deploying it to Docker and AWS Elastic Beanstalk). So I define my DB config settings like this:

define('DB_NAME',     getenv("RDS_DB_NAME"));
define('DB_USER',     getenv("RDS_USERNAME"));
define('DB_PASSWORD', getenv("RDS_PASSWORD"));
define('DB_HOST',     getenv("RDS_HOSTNAME"));

This works great in multiple environments, but WP CLI doesn't pick up the settings properly. It looks like the culprit is these lines:

https://github.com/wp-cli/wp-cli/blob/v1.0.0/php/class-wp-cli.php#L1011-L1026

Passing in the new environment into proc_open will replace the parent environment, thus replacing any environment variables that exist when invoking the CLI. I'm curious, why does this need to pass a new environment? Couldn't we just pass NULL there to inherit the parent environment?

@bgeihsgt
Copy link
Author

Forgot to mention I'm using wp rewrite structure to update permalink rules. It looks like #3640 is the exact issue I'm hitting.

I think the right solution here is to just pass NULL for the env parameter. That way it will inherit the environment of the parent PHP process. @danielbachhuber what do you think?

@danielbachhuber
Copy link
Member

I think the right solution here is to just pass NULL for the env parameter. That way it will inherit the environment of the parent PHP process. @danielbachhuber what do you think?

Oh, huh. Have you tested to verify the environment variables are actually passed through?

@bgeihsgt
Copy link
Author

I haven't tested it yet, was going off of the docs here: http://php.net/manual/en/function.proc-open.php

Will test shortly.

@bgeihsgt
Copy link
Author

What's the easiest way to make a change and test it locally? (sorry, I'm a PHP n00b)

@bgeihsgt
Copy link
Author

For now going with installing it as a project and testing it that way

bgeihsgt pushed a commit to bgeihsgt/wp-cli that referenced this issue Jan 12, 2017
This fixes wp-cli#3729. proc_open will inherit the parent environment if you
pass NULL for the environment parameter
(http://php.net/manual/en/function.proc-open.php). I've verified that
this works properly by testing this fix against my wp-config that
contained environment variables.
@bgeihsgt
Copy link
Author

@danielbachhuber I tested it locally and verified it works. Please see PR #3730 above.

@danielbachhuber
Copy link
Member

Interesting. Learn something new every day!

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

Successfully merging a pull request may close this issue.

2 participants