Skip to content

Instantly share code, notes, and snippets.

@vidbina
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vidbina/cc7ac313911b8843b896 to your computer and use it in GitHub Desktop.
Save vidbina/cc7ac313911b8843b896 to your computer and use it in GitHub Desktop.
helper to load the right PHP version as specified in the .php-version file with phpbrew
# This helper will switch the PHP version using phpbrew provided that there is a .php-version present
# Call this helper by calling it with the source command: source FILENAME
# NOTE: You do need to install the proper version yourself in order for this to work (phpbrew install VERSION)
if [ -f .php-version ]
then
VERSION=$(<.php-version)
printf "Loading PHP v$VERSION\n"
phpbrew use $VERSION
else
printf "A .php-version containing the version is needed\n\n"
printf "You could create a .php-version file by running the following command:\n"
printf " echo 5.5.12 > .php-version\n\n"
printf "Do replace 5.5.12 for the version you really need ;)\n"
fi
@vidbina
Copy link
Author

vidbina commented May 31, 2014

Now you can switch to the proper PHP version by just running source .env from the project's root directory in the command prompt. Yes, you will need to do this every time you open a new terminal session, but source .env still beats typing phpbrew use VERSION.

Pros:

  • get going with less keystrokes (source .env vs. phpbew use VERSION)
  • don't worry about the version you need to load as .php-version gives you a reason not to 😉

Cons:

  • you need a .env file in the root of every project for which you want to use phpbrew in combination with the .php-version file (you could save the .env file as ~/.phpbrew/phpversion-helper and symlink it from every project directory using ln -s ~/.phpbrew/phpversion-helper .env

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