Skip to content

Provide a more helpful error message when php-cgi is detected #5703

@gjedeer

Description

@gjedeer

I tried running wp-cli in a cpanel environment and the experience was as following:

[user@hwd-wp ~]$ wget https://github.com/wp-cli/wp-cli/releases/download/v2.7.1/wp-cli-2.7.1.phar
(....)
2022-11-18 09:55:09 (60,9 MB/s) - ‘wp-cli-2.7.1.phar’ saved [6729511/6729511]

[user@hwd-wp ~]$ chmod +x wp-cli-2.7.1.phar 
[user@hwd-wp ~]$ php wp-cli-2.7.1.phar 
Status: 500 Internal Server Error
Content-type: text/html; charset=UTF-8

I've then found in error log that the cause for this is Undefined constant "WP_CLI\Utils\STDOUT", which in turn is caused by cPanel providing php-cgi instead of php-cli:

[user@hwd-wp public_html]$ php -v
PHP 8.1.12 (cgi-fcgi) (built: Nov  9 2022 17:32:43)
Copyright (c) The PHP Group
Zend Engine v4.1.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.12, Copyright (c), by Zend Technologies

Since cPanel is a pretty popular environment, maybe it would be good if wp-cli detected when it's not ran using wp-cli and returned a more user friendly message? Two solutions come to my mind:

  1. explicit php_sapi_name check and die() with a friendly error message if it's not a supported SAPI
  2. a catch-all exception handler printing the error (which is not needed in php-cli, so maybe php_sapi_name() needs to be used?)

It was not obvious to me that I should look for output of shell script in an error log - which is of course because of cPanel not wp-cli.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions