0

I've installed a version of Wordpress using composer, and modified the default folders for the content (/wp-content) and the core (/wp).

My wp-config.php gets its DB_NAME, DB_USERNAME, DB_PASSWORD from environment variables defined in the .htaccess file.

I am able to connect to my wordpress instance using my browser, so the connection information in there is fine.

I have not managed to get wp-cli to run on this instance. wp-cli --debug outputs:

Debug (bootstrap): No readable global config found (0.014s)
Debug (bootstrap): No project config found (0.016s)
Debug (bootstrap): No package autoload found to load. (0.261s)
Debug (bootstrap): ABSPATH defined: /path/to/core/ (0.272s)
Debug (bootstrap): Begin WordPress load (0.288s)
Debug (bootstrap): wp-config.php path: /path/to/wp-config.php (0.292s)
Error: Error establishing a database connection

(I've double checked these paths and they are correct)

I keep getting that same error. I've tried installing a clean instance using composer, but this time :

  • without any plugin
  • without any theme
  • by defining the DB_NAME, DB_USERNAME, DB_PASSWORD directly in the wp-config.php file rather than getting those from env. variables.
  • but I kept the custom folder structure /wp for the core and /wp-content for the content

Still the same error... Am I missing something ? Is it the custom folder structure that wp-cli doesn't like ?

Executing wp-cli --info outputs this :
PHP binary: /usr/bin/php
PHP version:    5.5.36
php.ini used:
WP-CLI root dir:    phar://wp-cli.phar
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 0.24.1

I'm on Max OS X El Capitan.

Thanks a lot for your help,

Julien

2 Answers 2

1

If you are calling WP-CLI from the parent directory you need to tell it where core is using --path

$ wp --path=path/to/core

Some more details here: http://wp-cli.org/config/

You can set also set this with a config file wp-cli.yml that contains

path: path/to/core

Details: http://wp-cli.org/config/#config-files

3
  • Hey, thanks kraftner ! I've tried wp --path htdocs/wp when I execute if from above htdocs but it still doesn't work... It finds the correct path to my w^-config.php file, so I really dont't get why it doesn't work. Any chance it could be something like the version of PHP or the way the connection to MySQL is supposed to work ? Commented Sep 19, 2016 at 18:15
  • Ahhhh... Found : I installed wp-cli outside of my VM, so the localhost it finds in my wp-config.phpdoesn't quite work :) Commented Sep 19, 2016 at 18:35
  • 1
    :) Good you resolved it. Maybe you want to add that as an answer too and accept it. I guess this is a pretty common mistake to make so other would profit from this.
    – kraftner
    Commented Sep 20, 2016 at 10:51
0

An old thread, I know but I recently has this problem. I had prepended the path to composer's wp to the PATH env var and the following produced the expected output:

% wp --info
OS: Darwin 21.6.0 Darwin Kernel Version 21.6.0: Mon Jun 24 00:56:10 PDT 2024; root:xnu-8020.240.18.709.2~1/RELEASE_X86_64 x86_64
Shell:  /bin/zsh
PHP binary: /usr/local/bin/php
PHP version:    8.3.11
php.ini used:   /usr/local/etc/php/8.3/php.ini
MySQL binary:   /usr/local/bin/mysql
MySQL version:  mysql  Ver 9.0.1 for macos12.7 on x86_64 (Homebrew)
SQL modes:  
WP-CLI root dir:    /usr/local/var/www/wordpress/wp-content/plugins/wp-simple-google-appointments/vendor/wp-cli/wp-cli
WP-CLI vendor dir:  /usr/local/var/www/wordpress/wp-content/plugins/wp-simple-google-appointments/vendor
WP_CLI phar path:   
WP-CLI packages dir:    
WP-CLI cache dir:   /Users/XxXxXxX/.wp-cli/cache
WP-CLI global config:   
WP-CLI project config:  
WP-CLI version: 2.11.0

But everything else exited with no output and with exit code zero. The --debug flag did not show any errors.

This was because I was missing the following (from the require-dev section) in my composer.json:

        "wp-cli/db-command" : "^2",
        "wp-cli/entity-command" : "^2",
        "wp-cli/extension-command" : "^2",
        "wp-cli/package-command" : "^2"

By default, wp-cli/wp-cli just installs the WPCLI container without any WPCLI commands installed!

EDIT: Or require wp-cli/wp-cli-bundle for a selection of most WPCLI commands.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.