WP-CLI Doesn't Work with Modified WP-Config

We use a wp-config-local.php for our local environments. The wp-config.php automatically loads wp-config-local.php if it exists. This works fine, except when we try to run WP-CLI commands.

When we attempt to run a WP-CLI command, we get an error about a database connection.

When I look at the “Database” tab in local, it is unable to find most of the values because it is looking in wp-config.php (instead of wp-config-local.php).

Is there a way to tell Local to use wp-config-local.php? Or another work around for this?

Hey @jeremyenglert

Can you provide a little more info on what’s going wrong?

  • Do you have the exact connection error that is being reported?
  • Where is the wp-cli command being run - on the host machine, or inside the container?

Hi Ben!

Here is the error output:

Last login: Fri Apr 19 14:50:24 on ttys000
Jeremys-MacBook-Pro:~ jeremyenglert$ /Users/jeremyenglert/Library/Application\ Support/Local\ by\ Flywheel/ssh-entry/Bykr6g7j7.sh ; exit;
root@f5c5dbc1a772:/# wp info

Fatal error: Cannot redeclare wp_get_server_protocol() (previously declared in /app/public/wp-includes/load.php:15) in /app/public/wp-includes/load.php on line 21

Call Stack:
    0.0001     345408   1. {main}() /usr/local/bin/wp:0
    0.0105     750640   2. include('phar:///usr/local/bin/wp/php/boot-phar.php') /usr/local/bin/wp:4
    0.0106     757584   3. include('phar:///usr/local/bin/wp/php/wp-cli.php') phar:///usr/local/bin/wp/php/boot-phar.php:8
    0.0108     767680   4. WP_CLI\bootstrap() phar:///usr/local/bin/wp/php/wp-cli.php:23
    0.0612    6780512   5. WP_CLI\Bootstrap\LaunchRunner->process() phar:///usr/local/bin/wp/php/bootstrap.php:75
    0.0612    6780552   6. WP_CLI\Runner->start() phar:///usr/local/bin/wp/php/WP_CLI/Bootstrap/LaunchRunner.php:23
    0.0663    6858288   7. WP_CLI\Runner->load_wordpress() phar:///usr/local/bin/wp/php/WP_CLI/Runner.php:1032
    5.4033   63964760   8. require('/app/public/wp-settings.php') phar:///usr/local/bin/wp/php/WP_CLI/Runner.php:1105

root@f5c5dbc1a772:/# 

This is being run inside the container (SSHing into the install).

@jeremyenglert

Can you take a look at this Github issue:

and in particular this comment from that issue:

I simply commented out require_once(ABSPATH . 'wp-settings.php'); in wp-config-local.php (and left it as-is in wp-config.php ). This solved my wp-cli problem and doesn’t appear (so far) to have any adverse effects (since wp-settings.php does still get loaded in wp-config.php )

Let me know if that fixes things for you.

That appears to fix the issue! Big thanks Ben!