Last active
October 19, 2025 05:33
-
-
Save dlundgren/5ebbee7d2d7e30ca8f0df4d4834022d2 to your computer and use it in GitHub Desktop.
phpenv extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # Summary: Install PHP version | |
| # | |
| # Usage: phpenv brew-ext mongodb 8.0 | |
| set -e | |
| [ -n "$PHPENV_DEBUG" ] && set -x | |
| VERSION="$1" | |
| # check for shivammathur/php and tap if not installed | |
| TAPPED=$(brew tap | grep shivammathur/extensions) | |
| if [ $? -eq 1 ]; then | |
| brew tap shivammathur/extensions | |
| fi | |
| echo "installing ${VERSION}" | |
| export HOMEBREW_NO_AUTO_UPDATE=1 | |
| export HOMEBREW_NO_ENV_HINTS=1 | |
| brew install shivammathur/extensions/php@${VERSION} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # Summary: Install PHP version | |
| # | |
| # Usage: phpenv brew-install 8.0 | |
| set -e | |
| [ -n "$PHPENV_DEBUG" ] && set -x | |
| VERSION="$1" | |
| # check for shivammathur/php and tap if not installed | |
| TAPPED=$(brew tap | grep shivammathur/php) | |
| if [ $? -eq 1 ]; then | |
| brew tap shivammathur/php | |
| fi | |
| for brew_path in $(ls $HOMEBREW_CELLAR | grep php) | |
| do | |
| # we can't rely on the version to come from the file path | |
| version_path=$(ls $HOMEBREW_CELLAR/$brew_path | head -n 1) | |
| version=$($HOMEBREW_CELLAR/$brew_path/$version_path/bin/php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;") | |
| if [ "$version" == "$VERSION" ]; then | |
| echo "PHP ${VERSION} already installed" | |
| exit 1 | |
| fi | |
| done | |
| # if we haven't exited by now we can install the requested version | |
| echo "installing ${VERSION}" | |
| export HOMEBREW_NO_AUTO_UPDATE=1 | |
| export HOMEBREW_NO_ENV_HINTS=1 | |
| brew install shivammathur/php/php@${VERSION} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # Summary: Scan for new PHP versions from brew and link as MAJOR.MINOR | |
| # | |
| # Usage: phpenv scan | |
| set -e | |
| [ -n "$PHPENV_DEBUG" ] && set -x | |
| for brew_path in $(ls $HOMEBREW_CELLAR | grep php) | |
| do | |
| # we can't rely on the version to come from the file path | |
| version_path=$(ls $HOMEBREW_CELLAR/$brew_path | head -n 1) | |
| version=$($CELLAR/$brew_path/$version_path/bin/php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;") | |
| if [ -L "${PHPENV_ROOT}/versions/${version}" ]; then | |
| unlink "${PHPENV_ROOT}/versions/${version}" | |
| fi | |
| if [ ! -e "${PHPENV_ROOT}/versions/${version}" ]; then | |
| echo "Linking ${version} to $HOMEBREW_CELLAR/${brew_path}/${version_path}" | |
| ln -sf "$HOMEBREW_CELLAR/${brew_path}/${version_path}" "${PHPENV_ROOT}/versions/${version}" | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment