Last active
August 29, 2015 14:02
-
-
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 file contains 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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
.env
into the your project's root directory.php-version
file containing the PHP version you want (it is up to you to install the needed PHP versions with phpbrew)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, butsource .env
still beats typingphpbrew use VERSION
.Pros:
source .env
vs.phpbew use VERSION
)Cons:
.env
file in the root of every project for which you want to usephpbrew
in combination with the.php-version
file (you could save the .env file as ~/.phpbrew/phpversion-helper and symlink it from every project directory usingln -s ~/.phpbrew/phpversion-helper .env