Created
December 2, 2019 20:52
-
-
Save sasa-b/883fd9810f773e3e200bdf8ea073f93b to your computer and use it in GitHub Desktop.
A small script for easier management of multiple version of PHP with Homebrew on macOS
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
#!/usr/bin/env php | |
<?php | |
$ver = isset($argv[1]) ? $argv[1] : null; | |
if (!$ver) { | |
echo "Missing version argument\n"; | |
exit(1); | |
} | |
if (!is_numeric($ver) || !preg_match("/^[5-9]\.[0-9]$/", $ver)) { | |
echo "Invalid version format, version number must be a decimal value with precision of one, e.g. 7.0\n"; | |
exit(2); | |
} | |
$user = get_current_user(); | |
$bash_profile = file_get_contents("/Users/$user/.bash_profile"); | |
file_put_contents("/Users/$user/.bash_profile", preg_replace("/php@\d+\.\d+/", "php@$ver", $bash_profile)); | |
echo "\n"; | |
echo "PHP set to: $ver\n"; | |
echo "Restart the terminal for the changes to take effect.\n"; | |
echo "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. Thanks for your idea shared through https://sasablagojevic.com/running-multiple-versions-of-php-on-macos-with-homebrew !
I changed it to .sh script and improved a little bit making it even more user friendly :)
https://gist.github.com/codingJouda/088ac3a6331bf6ddb81bde9c5fda8331
Best regards