Question

WP-CLI - Managed database connection issues

Trying to use wp-cli with our managed database from our droplet, wordpress works and connects fine on the front end and admin, but connections via wp-cli just give me a " Error establishing a database connection."

Obviously its reading from the same wp-config file, and connecting as the same user/port/host and from the same IP so that is all valid, any idea whys not connecting, as its Terminal, does the managed database need to be configured to accept connections from that port? or the firewall on the server likewise?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

I have a couple of suggestions:

  • Make sure that you are running the WP-CLI commands while inside the directory that your WordPress website is installed in. The default is /var/www/html unless you’ve installed it in another directory.

  • Make sure that your PHP CLI version is the same as the version used by your frontend/webserver. You can check that with the php -v command. If the version does not match the version that your web server uses.

If it is the latter, you can run the WP CLI binary with a specific version by specifying it explicitly:

  1. /usr/bin/php8.0 /usr/bin/wp

Let me know how it goes.

Best,

Bobby