welaika / wordmove

Multi-stage command line deploy/mirroring and task runner for Wordpress
https://wptools.it/wordmove
MIT License
1.87k stars 165 forks source link

Can't connect to database when using "wpcli". #474

Closed electricarts closed 6 years ago

electricarts commented 6 years ago

I can't push or pull databases when using wpcli as sql_adapter as "global" entry in movefile.yml. The error message says: Error when establishing a database connection. Username or password are incorrect or the database server at localhost can't be reached. (translated from german).

/Users/mario/.rvm/gems/ruby-2.4.0/gems/wordmove-3.0.2/lib/wordmove/deployer/base.rb:107:in `run': Return code reports an error (Wordmove::ShellCommandError)
    from /Users/mario/.rvm/gems/ruby-2.4.0/gems/wordmove-3.0.2/lib/wordmove/deployer/ssh/wpcli_sql_adapter.rb:11:in `adapt_local_db!'
    from /Users/mario/.rvm/gems/ruby-2.4.0/gems/wordmove-3.0.2/lib/wordmove/deployer/ssh.rb:36:in `push_db'
    from /Users/mario/.rvm/gems/ruby-2.4.0/gems/wordmove-3.0.2/lib/wordmove/cli.rb:103:in `block in push'
    from /Users/mario/.rvm/gems/ruby-2.4.0/gems/wordmove-3.0.2/lib/wordmove/cli.rb:42:in `block in handle_options'
    from /Users/mario/.rvm/gems/ruby-2.4.0/gems/wordmove-3.0.2/lib/wordmove/cli.rb:41:in `each'
    from /Users/mario/.rvm/gems/ruby-2.4.0/gems/wordmove-3.0.2/lib/wordmove/cli.rb:41:in `handle_options'
    from /Users/mario/.rvm/gems/ruby-2.4.0/gems/wordmove-3.0.2/lib/wordmove/cli.rb:102:in `push'
    from /Users/mario/.rvm/gems/ruby-2.4.0@global/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
    from /Users/mario/.rvm/gems/ruby-2.4.0@global/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/mario/.rvm/gems/ruby-2.4.0@global/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch'
    from /Users/mario/.rvm/gems/ruby-2.4.0@global/gems/thor-0.19.4/lib/thor/base.rb:444:in `start'
    from /Users/mario/.rvm/gems/ruby-2.4.0/gems/wordmove-3.0.2/exe/wordmove:6:in `<top (required)>'
    from /Users/mario/.rvm/gems/ruby-2.4.0/bin/wordmove:23:in `load'
    from /Users/mario/.rvm/gems/ruby-2.4.0/bin/wordmove:23:in `<main>'
    from /Users/mario/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `eval'
    from /Users/mario/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `<main>'

The wordmove doctor shows everything green. Updated to the latest wp-cli version (1.5.1)

When using "default" as sql_adapter everything works like a charm! So i don't know whats wrong when using the wpcli sql_adapter.

alessandro-fazzi commented 6 years ago

Hello @electricarts ,

I fear that you'll get the same error also simply trying to issue wp help from inside your project :(

Unfortunately that should really means that wp-cli can't connect to the database; but keep in mind that Wordmove does nothing to configure wp-cli, so wp-cli must work on its own. Moreover - usually - when wp-cli can't connect to the database, neither WordPress can; have you tried to reach WordPress and see what it tells?

I'd try to compare your wp-config.php db credentials against the ones you wrote in movefile.yml.

electricarts commented 6 years ago

Hi @pioneerskies,

the credentials are correct and the same. How could it work with the default sql_adapter without any problems when the credentials would be different in wp-config.php and movefile?

alessandro-fazzi commented 6 years ago

default totally bypasses and ignores wordpress, thus not reading wp-config.php configurations and relying only on the movefile.yml.

wp-cli has its standalone connection. I'd like to have faith in wp-cli working when WordPress is working...but, my bad: can't figure out what's up there. Is actually WordPress working? Just one sure thing: connection between wp-cli and the database is not managed by wordmove; I suggest to troubleshoot wp-cli alone before to retry with wordmove :(

Other wp commands? What are they saying?

electricarts commented 6 years ago

A probably stupid question: Does wp-cli have to be installed on the live server (shared hosting) too? Sorry for this question, but I'm more of a pixel pusher than the server admin. ;-)

alessandro-fazzi commented 6 years ago

No, @electricarts , you need wp-cli locally only. Wordmove will manage to do search-replace locally in any case.

electricarts commented 6 years ago

I found out what I did wrong. I use MAMP (Pro) and of course I have to tell wp-cli which PHP version is used and where to find it. Otherwise wp-cli tries to access the Mac's PHP installation and not the MAMP PHP installation.

So for everyone who may have the same problem: I have added the following entries to my .bash_profile (~/.bash_profile):

MAMP Madness

export PATH=/Applications/MAMP/Library/bin:$PATH PHP_VERSION=ls /Applications/MAMP/bin/php/ | sort -n | tail -1 export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH

Restart the Terminal and everything works like a charm.

Found the solution here: https://wordpress.stackexchange.com/questions/235483/mamp-pro-wp-cli-error-error-establishing-a-database-connection

alessandro-fazzi commented 6 years ago

Thanks @electricarts for you precious feedback.

I've updated our MAMP dedicated wiki page with PHP_VERSION part.

Could we thus close this issue?

electricarts commented 6 years ago

Hi @pioneerskies, of course we can close this issue. Actually, it wasn't an issue. It was my unknowingness. ;-)

humblecoder commented 4 years ago

TLDR; Currently lacking sleep, might be wrong: WPCLI relying on wp-config.php not cool, prefer to rely on movefile.yml


Apologies for resurrecting this bug, but I have the same issue for different reasons. I think requiring WPCLI might be shortsighted (or perhaps I am 🤔 ). I serve all of my local WP sites from tools such as Vagrant with local drives aliased for Vagrant to read/serve as needed. However, this inherently means that my wp-config.php isn't locally relevant and therefore isn't useful to WPCLI. Now, I could vagrant ssh into my instance whenever I wanted to deploy, but that seems like a hassle.

At the very least, it would be nice if wordmove could forward relevant db values to WPCLI.

alessandro-fazzi commented 4 years ago

Hello @humblecoder ,

I think you should open a new discussion or a feature request if you have a clear vision on how the things could work for you.

Some notes:

It can also easily utilize Vagrant’s ssh helper command to figure out the SSH parameters, by piping the WP-CLI command to vagrant ssh using the vagrant scheme like --ssh=vagrant:default where default is the Vagrant machine name/id, or if defined as an alias like the examples below. Some Vagrant boxes ship this by default so you can use WP-CLI from the host machine out-of-the-box.

ref

Looking forward to read your new issue ;)