Skip to content

Instantly share code, notes, and snippets.

@indytechcook
Forked from Sir-Arturio/php-switch
Created September 24, 2012 12:02
Show Gist options
  • Save indytechcook/3775631 to your computer and use it in GitHub Desktop.
Save indytechcook/3775631 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.
brew unlink phpPackage
brew link phpPackage
# 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
# my version of running apache http://drupal.org/project/feather
feather restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment