wp-cli / wp-cli

⚙️ WP-CLI framework

Home Page:https://wp-cli.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WP_CLI_PHP ignored even when installing from deb not phar

sshankar-rks opened this issue · comments

Bug Report

--- ✅ If you are in the correct location now... --->

Describe the current, buggy behavior

wp-cli installed from here
Ubuntu 22.04
PHP is PHP-FPM 8.1 (/usr/sbin/php-fpm8.1)
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
WP_CLI_PHP="/usr/sbin/php-fpm8.1"

wp cli info shows the PHP used is php from /usr/bin, not WP_CLI_PHP as expected

Documentation says:
"WP_CLI_PHP – PHP binary path to use when overriding the system default (only works for non-Phar installation)."
Used to work with 2.5.0 deb file

Workaround
I tried this workaround.
But since /usr/local/wp is actually a script, not a php file, that workaround fails.

What I did:
Created a symbolic link from /usr/sbin/php-fpm8.1 to /usr/sbin/php
Then changed system path
PATH="/usr/sbin:$PATH"

That isn't a change I want to do. That changes the entire system's PHP version .

(Paste the output of "wp cli info" into this box)

OS:     Linux 5.4.0-132-generic #148-Ubuntu SMP Mon Oct 17 16:02:06 UTC 2022 x86_64
Shell:
PHP binary:     /usr/bin/php8.1
PHP version:    8.1.2-1ubuntu2.14
php.ini used:   /etc/php/8.1/cli/php.ini
MySQL binary:   /usr/bin/mysql
MySQL version:  mysql  Ver 8.0.35-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))
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:       /
WP-CLI packages dir:
WP-CLI cache dir:       /root/.wp-cli/cache
WP-CLI global config:   /home/wordpress/wp-cli.local.yml
WP-CLI project config:
WP-CLI version: 2.9.0

Expected behavior
The WP_CLI_PHP variable (and it's sibling, WP_CLI_PHP_ARGS) should both work whether using phar install or not.

Thanks for the report, @sshankar-rks.

I'm not an expert in the debian build but, AFAIK, it's just bundling the Phar file:

https://github.com/wp-cli/wp-cli-bundle/blob/8094b100cca467fe32a58e02a7ffe43ce26061b8/utils/wp-cli-updatedeb.sh#L45-L49

I don't think there have been any substantial changes between 2.5.0 and 2.9.0:

https://github.com/wp-cli/wp-cli-bundle/commits/8094b100cca467fe32a58e02a7ffe43ce26061b8/utils/wp-cli-updatedeb.sh

Can you re-test with the 2.5.0 binary?

I used the 2.5.0 binary for a couple of years now and wp cli info now shows changed locations for both executable and ini file.

Here is the output from the older version:
OS: Linux 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
Shell:
PHP binary: /usr/sbin/php-fpm7.4
PHP version: 7.4.3-4ubuntu2.19
php.ini used: /usr/bin/php-cli.ini
MySQL binary: /usr/bin/mysql
MySQL version: mysql Ver 8.0.35-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
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: /var/lib/www
WP-CLI packages dir:
WP-CLI global config: /home/wordpress/wp-cli.local.yml
WP-CLI project config:
WP-CLI version: 2.5.0

I think the issue is that there is no supported way to change the PHP version in the current and future versions of WP-CLI.

@danielbachhuber @sshankar-rks IMHO #5672 can be a root cause of this issue.

@wojsmol So, stated another way:

  1. The reported PHP binary was incorrect with php-wpcli_2.5.0_all.deb
  2. The reported PHP binary became correct when #5672 was applied.
  3. The deb file has never supported WP_CLI_PHP.

Are these three statements correct?

If they are, I think we can update the deb file to support WP_CLI_PHP. However, I think we'll need to wait until 3.0.0 because it would technically be a breaking change.

For a complete fix, WP_CLI_PHP_ARGS also needs to be supported in the deb file.
And the php.ini file used must be the one seen in wp-cli's output.