Skip to content

Instantly share code, notes, and snippets.

@benedmunds
Created March 27, 2014 02:29
Show Gist options
  • Save benedmunds/9798806 to your computer and use it in GitHub Desktop.
Save benedmunds/9798806 to your computer and use it in GitHub Desktop.
Hacky PHP Switch script
#!/bin/bash
# php switch for homebrew
# $ brew tap josegonzalez/php && brew install php53 --with-mysql && brew install php54 --with-mysql
# modified from original basic script from somewhere on the interweb, I don't remember where
# Might as well ask for password up-front, right?
sudo -v
VERSION_FILE="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/php-switch.version"
if [[ ! -f $VERSION_FILE ]]; then
echo "5.4" > $VERSION_FILE
fi
version=`cat $VERSION_FILE`
if [[ $version == 5.3 ]]; then
ln -sf `brew list php54 | grep libphp` /usr/local/lib/libphp5.so
brew unlink php54 && brew link php54 --overwrite
export PATH="$(brew --prefix php54)/bin:$PATH"
echo "Switched to 5.4"
echo `brew info php54 | head -1`
echo "5.4" > $VERSION_FILE
else
ln -sf `brew list php53 | grep libphp` /usr/local/lib/libphp5.so
brew unlink php53 &&brew link php53 --overwrite
export PATH="$(brew --prefix php53)/bin:$PATH"
echo "Switched to 5.3"
echo `brew info php53 | head -1`
echo "5.3" > $VERSION_FILE
fi
sudo apachectl restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment