Created
December 16, 2015 14:47
-
-
Save Thijzer/66ad816215f2b5ee9af4 to your computer and use it in GitHub Desktop.
.files php version switcher
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
#!/bin/bash | |
if [ $# -ne 1 ]; then | |
echo "Usage: sphp [phpversion]" | |
exit 1 | |
fi | |
currentversion="`php -r \"echo str_replace('.', '', substr(phpversion(), 0, 3));\"`" | |
newversion="$1" | |
brew list php$newversion 2> /dev/null > /dev/null | |
if [ $? -eq 0 ]; then | |
echo "PHP version $newversion found" | |
echo "Unlinking PHP version $currentversion... " | |
brew unlink php$currentversion 2> /dev/null > /dev/null | |
echo "Linking new binaries..." | |
brew link --overwrite php$newversion | |
echo "Linking new modphp addon..." | |
sudo ln -sf `brew list php$newversion | grep libphp` /usr/local/lib/libphp5.so | |
echo "Updating version file..." | |
pgrep -f /usr/sbin/httpd 2> /dev/null > /dev/null | |
if [ $? -eq 0 ]; then | |
echo "Restarting system Apache..." | |
sudo pkill -9 -f /usr/sbin/httpd | |
sudo /usr/sbin/apachectl -k restart > /dev/null 2>&1 | |
fi | |
pgrep -f /usr/local/Cellar/*/httpd 2> /dev/null > /dev/null | |
if [ $? -eq 0 ]; then | |
echo "Restarting homebrew Apache..." | |
sudo pkill -9 -f /usr/local/Cellar/*/httpd | |
sudo /usr/local/bin/apachectl -k restart > /dev/null 2>&1 | |
fi | |
echo "Done." | |
else | |
echo "PHP version $newversion was not found." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment