Skip to content

Instantly share code, notes, and snippets.

@fathurrohman26
Forked from yuki777/link-phps.bash
Created December 19, 2023 12:06
Show Gist options
  • Save fathurrohman26/740afa96feaa20cfe07d9e5dcfa08d62 to your computer and use it in GitHub Desktop.
Save fathurrohman26/740afa96feaa20cfe07d9e5dcfa08d62 to your computer and use it in GitHub Desktop.
Link the php installed by Brew to ~/.phpenv/versions
@fathurrohman26
Copy link
Author

Usage:

curl -fsSL https://gist.githubusercontent.com/fatfatcocofat/740afa96feaa20cfe07d9e5dcfa08d62/raw/2a2f0ff6b295c5075216b3e4cfc3e0b3b37af6af/link-phps.bash | bash

@fathurrohman26
Copy link
Author

Notes on brew upgrade

When php is upgraded by brew upgrade, symlink will be broken, so you need to re-run the link.

curl -fsSL https://gist.githubusercontent.com/fatfatcocofat/740afa96feaa20cfe07d9e5dcfa08d62/raw/2a2f0ff6b295c5075216b3e4cfc3e0b3b37af6af/link-phps.bash | bash

@fathurrohman26
Copy link
Author

Tests

# set version
cd /tmp         && phpenv global 8.1 # set 8.1 as a global
cd /tmp/php74   && phpenv local  7.4 # pin 7.4 in this dir
cd /tmp/php80   && phpenv local  8.0 # pin 8.0 in this dir
cd /tmp/php81   && phpenv local  8.1 # pin 8.1 in this dir

# test version
cd /tmp         && php -v # => 8.1
cd /tmp/php74   && php -v # => 7.4
cd /tmp/php80   && php -v # => 8.0
cd /tmp/php81   && php -v # => 8.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment