Skip to content

Instantly share code, notes, and snippets.

@sasa-b
Created December 2, 2019 20:52
Show Gist options
  • Save sasa-b/883fd9810f773e3e200bdf8ea073f93b to your computer and use it in GitHub Desktop.
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
#!/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";
@codingJouda
Copy link

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

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