Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEVX-3831] Allow PHP binary to be selected via an environment variable. #2658

Open
wants to merge 1 commit into
base: 4.x
Choose a base branch
from

Conversation

greg-1-anderson
Copy link
Member

Create a bash wrapper that allows users to select a specific PHP version via an environment variable.

For users who install the terminus.phar binary by the existing documented approach, there is no change in behavior; the old way continues to work, but does not allow the PHP binary to be selected (only the one in the $PATH may be used).

For users who install the new terminus script in their $PATH, and also put terminus.phar in their $PATH (without renaming it), the following behavior is now supported:

$ php --version
PHP 7.4.33 (cli) (built: Nov 22 2024 10:43:27) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies
$ terminus --version

Sorry, your PHP version (7.4.33) is no longer supported.
Upgrade to PHP 8.2 or newer to use Terminus 4. For PHP versions prior to 8.2, downgrade to Terminus 3.x.

For more information, see https://pantheon.io/docs/terminus/updates#php-version-compatibility-matrix
$ export TERMINUS_PHP=/opt/homebrew/Cellar/[email protected]/8.3.14/bin/php
$ $TERMINUS_PHP --version
PHP 8.3.14 (cli) (built: Nov 19 2024 15:14:23) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.14, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.14, Copyright (c), by Zend Technologies
$ terminus --version
Terminus 4.0.0-dev

@greg-1-anderson greg-1-anderson requested a review from a team as a code owner December 17, 2024 18:34
@greg-1-anderson
Copy link
Member Author

greg-1-anderson commented Dec 17, 2024

Simple terminus wrapper script:

#!/usr/bin/env sh

SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"

TERMINUS_EXECUTABLE="$SCRIPTPATH/terminus.php"

# If we can't find `terminus.php` next to `terminus`,
# look for `terminus.php` in the same directory.
if [ ! -f "$TERMINUS_EXECUTABLE" ]; then
  TERMINUS_EXECUTABLE="$SCRIPTPATH/terminus.phar"
fi

# If there is no `terminus.phar` nearby, check for one
# in the $PATH.
if [ ! -f "$TERMINUS_EXECUTABLE" ]; then
  TERMINUS_EXECUTABLE="terminus.phar"
fi

# Use the PHP binary indicated by $TERMINUS_PHP, or use
# the one in the $PATH if $TERMINUS_PHP is not set.
PHP="${TERMINUS_PHP=php}"

# Run Terminus with the selected version of PHP, passing
# through all parameters.
exec "$TERMINUS_PHP" "$TERMINUS_EXECUTABLE" "$@"

@greg-1-anderson greg-1-anderson force-pushed the terminus-wrapper-script branch 3 times, most recently from 411ce53 to e231b62 Compare December 18, 2024 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant