Skip to content

Bedrock compatibility #2

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

Closed
joshuafredrickson opened this issue Feb 21, 2025 · 5 comments
Closed

Bedrock compatibility #2

joshuafredrickson opened this issue Feb 21, 2025 · 5 comments

Comments

@joshuafredrickson
Copy link

Really liking this so far on standard WP sites.

For Bedrock sites, I receive the following error:

$ wp move pull staging

In Alias.php line 404:
                                                                              
  The command "wp eval "echo wp_get_upload_dir()['basedir'] ?? '';"" failed.  
                                                                              
  Exit Code: 1                                                                
                                                                              
  (Error: Error establishing a database connection.)

Note that both of the following commands return the expected paths:

wp eval "echo wp_get_upload_dir()['basedir'] ?? '';"  # /path/to/site/web/app/uploads
wp @staging eval "echo wp_get_upload_dir()['basedir'] ?? '';" # /path/to/release/web/app/uploads
@nlemoine
Copy link
Owner

nlemoine commented Feb 21, 2025

Hello @joshuafredrickson,

I'm also using Bedrock or similar and running move without any issues. Can you provide your wp-cli.yml? I have a clue on what's going wrong but need more information.

Also is your remote alias already installed?

@joshuafredrickson
Copy link
Author

joshuafredrickson commented Feb 21, 2025

Sure thing!

wp-cli.yml:

path: web/wp
server:
  docroot: web

@staging:
  ssh: site-staging/path/to/current
@production:
  ssh: site/path/to/current

ETA: site and site-staging are SSH aliases.

@nlemoine
Copy link
Owner

nlemoine commented Feb 25, 2025

Your configuration looks good.

Can you tell/confirm:

  • the failing command (not the main wp move pull {alias} command) is happening on your local env right?
  • what version of wp-cli are you running?
  • is your local env containerized (vagrant, docker, etc.)?

Looks like WordPress path is correctly found but for some reason, database connection is failing.

I just synced a Bedrock website without any issues. Maybe try to run a dummy command and debug what's going wrong:

// path/to/local/project/root/foo.php
<?php

WP_CLI::add_command( 'foo', function() {
    $result = WP_CLI::runcommand('eval "echo wp_get_upload_dir()[\'basedir\'] ?? \'\';"', [
        [
            'return'     => 'all',
            'exit_error' => false,
        ]
    ]);

    var_dump($result);
} );
# path/to/local/project/root/wp-cli.yml
# ...your initial configuration
require:
  - foo.php

And run:

wp foo

Without being able to reproduce your error, there's not so much more I can do.

@joshuafredrickson
Copy link
Author

joshuafredrickson commented Feb 25, 2025

To confirm, the failure is happening locally, wp-cli is 2.11.0, and I'm running valet.

I was able to track it down to this recent Bedrock commit. With it applied, the command fails due to $_SERVER no longer being populated with .env variables.

I'm not sure what the easiest solve is for this, but it seems like it might need to occur on the Bedrock side of things unless there's some wp-cli.yml magic that can be performed.

I tried adding this just for fun, and started going down a rabbit hole of composer conflicts before stopping.

require:
  - vendor/autoload.php
  - foo.php

env:
  DB_NAME: ${DB_NAME}
  DB_USER: ${DB_USER}
  DB_PASSWORD: ${DB_PASSWORD}
  DB_HOST: ${DB_HOST}

@nlemoine
Copy link
Owner

nlemoine commented Feb 25, 2025

Not sure you should require vendor/autoload.php in your wp-cli.yml file, your vendors will be loaded by web/wp-config.php.

Since this seems to be a Bedrock issue, I'm closing this. I think you can keep tracking the problem here: roots/bedrock#756

BTW, Bedrock shouldn't use putenv, it's not thread safe: https://jolicode.com/blog/what-you-need-to-know-about-environment-variables-with-php#thread-safety-of-getenv

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

No branches or pull requests

2 participants