Automattic / jurassic.ninja

A frontend to launching ephemeral WordPress instances that auto-destroy after some time
https://jurassic.ninja/
Other
70 stars 12 forks source link

CLI PHP version is not the same as the web PHP version #264

Open JPry opened 2 years ago

JPry commented 2 years ago

I recently spun up a JN site, and specified PHP 8.0. The site itself was configured correctly, but when I went to run commands using WP CLI, I discovered that the version of PHP being used for the command line interface is the default, currently PHP 7.4. This causes an PHP 8 features to trigger a fatal error when CLI is executed for the site.

Here is the output from wp --info on CLI:

wp --info
OS: Linux 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64
Shell:  /bin/bash
PHP binary: /opt/sp/php7.4/bin/php
PHP version:    7.4.30
php.ini used:   /etc/php7.4-sp/php.ini
MySQL binary:   /usr/bin/mysql
MySQL version:  mysql  Ver 14.14 Distrib 5.7.33, for Linux (x86_64) using  EditLine wrapper
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:   /srv/users/user95535f5e/apps/user95535f5e/public
WP-CLI packages dir:    
WP-CLI global config:   
WP-CLI project config:  
WP-CLI version: 2.6.0

Doing some digging, I see that /usr/bin/wp is a simple wrapper to call the wp-cli.phar file:

#!/bin/bash

export PATH=/opt/sp/php7.4/bin:$PATH
php /opt/sp/bin/wp-cli.phar "$@"

With this in mind, setting up the site should include mapping /usr/bin/wp to use the correct version of PHP based on the site options. It might be beneficial to also change the native PHP being called, but using WP CLI will likely be the more prevalent use case.

As a workaround, I found that the PHP 8 executable is available (along with other version), but it needs to be specified manually to work properly with WP CLI:

php8.0-sp /opt/sp/bin/wp-cli.phar --info
OS: Linux 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64
Shell:  /bin/bash
PHP binary: /opt/sp/php8.0/bin/php
PHP version:    8.0.20
php.ini used:   /etc/php8.0-sp/php.ini
MySQL binary:   /usr/bin/mysql
MySQL version:  mysql  Ver 14.14 Distrib 5.7.33, for Linux (x86_64) using  EditLine wrapper
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:   /srv/users/user95535f5e/apps/user95535f5e/public
WP-CLI packages dir:    
WP-CLI global config:   
WP-CLI project config:  
WP-CLI version: 2.6.0

Steps to reproduce

  1. Spin up a new site with Jurassic Ninja, specifying PHP 8 as the version
  2. Visit Dashboard > Tools > Site Health > Info. Look under the "Server" section to see the version of PHP being used
  3. From the command line, run wp --info or php --version to see that a different version of PHP is being used.
waclawjacek commented 1 month ago

The CLI version is controlled on the server and is not something the JN site controls. Unless you mean the Docker image defaults? In this case this is something that should be fixed. :)

JPry commented 1 month ago

@waclawjacek

Unless you mean the Docker image defaults?

No, for the actual Jurassic.ninja service.