Skip to content

Instantly share code, notes, and snippets.

@Sir-Arturio
Forked from torifat/php-switch
Created September 6, 2012 14:29
Show Gist options
  • Save Sir-Arturio/3656862 to your computer and use it in GitHub Desktop.
Save Sir-Arturio/3656862 to your computer and use it in GitHub Desktop.
a php switching utillity for homebrew
#!/bin/sh
# php switch for homebrew
# $ brew tap josegonzalez/php && brew install php53 --with-mysql && brew install php54 --with-mysql
# Please add '/usr/local/Cellar/php/bin' to the beginning of your PATH variable to enable the command line binaries.
# Might as well ask for password up-front, right?
sudo -v
# Check the command-line argument and create version variable.
if [ -z $1 ]
then
echo "*** Please provide a PHP version."
exit 1
fi
version=$1
shortVersion=$(echo "$version" | tr -d '.')
echo "Switching to: PHP $version"
# Check that the formula/package exists in homebrew and fetch PHP directory.
phpPackage="php$shortVersion"
phpDir="$(brew --prefix $phpPackage)"
if [ $? -eq 1 ]
then
echo "*** PHP directory not found. Version not installed from homebrew?\n"
exit 1
fi
echo "PHP dir: $phpDir"
# Regenerate link to the correct PHP directory.
phpLink="/usr/local/Cellar/php"
rm "$phpLink"
ln -s "$phpDir" "$phpLink"
# Change libphp5.so installation.
libSource=$(brew list "$phpPackage" | grep libphp)
if [ -z "$libSource" ]
then
echo "*** Could not find suitable libphp5.so for package $phpPackage."
exit
fi
echo "Library: $libSource"
ln -sf "$libSource" /usr/local/lib/libphp5.so
sudo apachectl restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment