Troubleshoot WP-CLI
Review solutions to common troubleshooting scenarios for WP-CLI.
This section provides solutions to common WP-CLI troubleshooting scenarios.
Terminus WP-CLI Silent Failure
The silent failure shown below occurs when executing terminus remote:wp commands on environments that use redirect logic without checking to confirm that WordPress is running via the command line:
Redirects cancel the PHP process before WP-CLI is executed.
Add php_sapi_name() != "cli" as a conditional statement to all redirect logic within wp-config.php to resolve this error:
Request to a Remote API Does Not Return Expected Response
The PHP 5.5 default is & and the PHP 5.3 default is &.
If the API expects & as an argument separator but receives & (for example, when using http_build_query), you can override the default arg_separator.output value by adding the following line to wp-config.php:
Actions and Filters in wp-config.php
Actions or filters that require CLI tools like WP-CLI might fail from wp-config.php, because the functions required are not yet accessible. Put these directives in an MU Plugin to resolve this issue.
Changes to WP-CLI on the Platform (January 15th 2024)
Before January 15th 2024
When using WP-CLI in a non-live environment, errors are included in the standard output (stdout) part of the response. When used over Terminus, errors are printed before the command output. This example shows the current state with any notice or warning displayed before the command output of wp_.
This makes it difficult to have a script that relies on capturing the value of a given command (i.e. config get or plugin list), as the errors also end up captured.
Starting January 15th 2024
When running WP-CLI, display_errors will be changed to standard error (stderr) in php.ini, so that errors can be handled separately from the actual command output. Three changes are notable here:
Errors go to stderr
With errors going to stderr, it is now possible to use the output of a WP-CLI command with no extra steps.
PHP errors will display in WP-CLI output
WP-CLI's error handling has been updated to direct PHP errors to stderr during CLI interactions across all environments. This change means that previously hidden notices or warnings from the Live environment are now visible in WP-CLI outputs. However, this update does not affect regular web requests and user interactions with the site, where these errors will continue to remain hidden.
Terminus now displays error messages after the command output
Because of Terminus’ specific handling of stdout and stderr, PHP errors now display after the command output instead of before.