Sage Theme : `wp acorn` -> Error establishing a database connection

Hello,

I have some problemes with acorn, and i don’t find my response in topics. I’ll like to use it for install a simple breadcrumb package for Sage 10 (Log1x/crumb).

I setup my bedrock project with Docker.

My command line wp seems working fine, here wp --info :

OS: Darwin 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:54:51 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6030 arm64
Shell:  /bin/zsh
PHP binary:     /opt/homebrew/Cellar/php/8.3.0/bin/php
PHP version:    8.3.0
php.ini used:   /opt/homebrew/etc/php/8.3/php.ini
MySQL binary:   
MySQL version:  
SQL modes:      
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /Users/olivierpierre/Dev/lab_espaces_publics/bedrock/web/app/themes/labeps-theme
WP-CLI packages dir:    
WP-CLI cache dir:       /Users/olivierpierre/.wp-cli/cache
WP-CLI global config:   
WP-CLI project config:  /Users/olivierpierre/Dev/lab_espaces_publics/bedrock/wp-cli.yml
WP-CLI version: 2.9.0

So when i use the command line with acorn i have this error Error establishing a database connection..

Thanks for help

https://discourse.roots.io/search?q=Acorn%20Error%20establishing%20a%20database%20connection

Sure, but i don’t find my response in all topics.

Where are you running the wp acorn command? Since you are using Docker, you need to be running that inside the container. I believe that’s the most common reason people run into that error.

2 Likes

Thanks for your answer !

I had an over problem with acorn No publishable resources for tag [] who is fixed with this topic acorn issue.

You ca configure wp-cli to work with specific path , see doc: Config – WP-CLI – WordPress.org

With “Local” , I usually use that following config, on a “simple wp stack” (i mean not Radicle or Bedrock but also work), in the root wp install folder (/public):

  • A w-cli.local.yaml file
path: /Users/xxx/LocalWebsites/your-website/app/public
url: https://your-website.test
require:
  - wp-cli/local.php
  - wp-cli/quiet.php
apache_modules:
  - mod_rewrite

and a folder `wp-cli` with two files:
// name: local.php

define('DB_NAME', 'local');
define('DB_USER', 'root');
define('DB_PASSWORD', 'root');
define('DB_HOST', '127.0.0.1:10228'); // or socket config

// name: quiet.php
error_reporting(0);
@ini_set('display_errors', 0);

On prod (or staging, or…) you can change those settings if needed.

Then all wp acorn & all wp commands work like a charm, everywhere in your IDE.
Cheers.

That’s pretty wild :sweat_smile: I would encourage you to use WP-CLI connected to the actual site that you’re working on

Have you taken a look at WP-CLI aliases? Setting up an alias for your environment would be a simpler and safer approach and would just look like:

$ wp @local acorn      # Execute WP-CLI command on the local environment
$ wp @production acorn # Execute WP-CLI command on the production environment

For folks using Trellis, running trellis alias will generate the WP-CLI aliases for you

1 Like

Hey @ben ,

Yeah, a bit crazy… but that’s me… ahaha.

Thanks, indeed wp-cli aliases seem to be made for that ^_^,
I’ll definitely check that out.

By the way, how “dangerous” is my code example?
Security wise or more error prone when running cli commands?

Thanks for the advice and help, have a nice weekend.