Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Setup multiple versions of PHP on OSX using homebrew
#!/usr/bin/env bash
# Use this script to install or re-install multiple versions of PHP
# You should be able to re-run the script multiple times; it will update/reinstall what it needs.
# Check OS
if [ "${OSTYPE//[0-9.]/}" != "darwin" ]; then
echo "This script is intended for OSX users."
exit
fi
# Install homebrew
if [ -z "$(which brew)" ]; then
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
# Intall taps
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
# Update/upgrade everything
brew update
brew upgrade --all
# Install multiple versions of php
brew install php55
brew link php55
echo "date.timezone = UTC" > /usr/local/etc/php/5.5/conf.d/date.ini
brew install php55-memcache
brew install php55-xdebug
brew install php55-xhprof
brew unlink php55
brew install php56
brew link php56
echo "date.timezone = UTC" > /usr/local/etc/php/5.6/conf.d/date.ini
brew install php56-memcache
brew install php56-xdebug
brew install php56-xhprof
brew unlink php56
brew install php70
brew link php70
brew install --HEAD homebrew/php/php70-memcached
brew install php70-xdebug
brew unlink php70
# Setup phpenv
brew install phpenv
if [ ! -d "${HOME}/.phpenv" ]; then
phpenv-install.sh
fi
if [ ! -d "${HOME}/.phpenv/versions" ]; then
mkdir -p "${HOME}/.phpenv/versions"
fi
find "${HOME}/.phpenv/versions" -maxdepth 1 -mindepth 1 -type l -delete
for version in $(find $(find /usr/local/Cellar -maxdepth 1 -mindepth 1 -name 'php[0-9][0-9]' ) -maxdepth 1 -mindepth 1 -type d 2>/dev/null); do
ln -s ${version} ${HOME}/.phpenv/versions/ 2>/dev/null
ln -s ${version} ${HOME}/.phpenv/versions/$(echo "${version}" | perl -p -e "s/.*(\d+\.\d+)\.(.+)$/\1/") 2>/dev/null
done
phpenv rehash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.