Last active
September 6, 2017 23:46
-
-
Save webbj74/4151020ef4f642fa80a6 to your computer and use it in GitHub Desktop.
Setup multiple versions of PHP on OSX using homebrew
This file contains hidden or 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
#!/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??' ) -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+)\.(\d+)$/\1/") 2>/dev/null | |
done | |
phpenv rehash |
Just found that -name 'php??'
will pick up phpmd
which is installed by brew now, so
find /usr/local/Cellar -maxdepth 1 -mindepth 1 -name 'php[0-9][0-9]'
Works very well
Loved this little installer. I created a fork of a fork of this to:
- Clean-up and fix for latest homebrew and MacOS.
- Simplify symlinking of versions using bash globs.
- Make homebrew PHP install consistent for each version.
- Other minor bug fixes and refactoring.
See https://gist.github.com/christopher-hopper/e8cfb878db9c1aaa8a21175f68607fdb
You may want to fetch and merge some of these changes yourself.
# Clone this Gist.
git clone https://gist.github.com/4151020ef4f642fa80a6.git phpenv-osx && cd $_
# Fetch my fork.
git remote add fork https://gist.github.com/e8cfb878db9c1aaa8a21175f68607fdb.git
git fetch --all --prune
# Merge latest fixes.
git merge fork/master
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The perl RE
only handles numeric minors, but
7.1.0-beta.1
and7.1.0-beta.1_2
make this fail. Seems like we could probably go ahead and just use.+
for the third+