Skip to content

Instantly share code, notes, and snippets.

@5818959
Created September 22, 2018 12:38
Show Gist options
  • Save 5818959/4e0a044a01cdbf346ee54da3f68ef58d to your computer and use it in GitHub Desktop.
Save 5818959/4e0a044a01cdbf346ee54da3f68ef58d to your computer and use it in GitHub Desktop.
Switch PHP versions in Mac OS

Switch PHP version

https://www.colinodell.com/blog/201808/automatically-switch-php-version-cd

For mac.

Create folder and symlink:

sudo mkdir /usr/alternatives
sudo ln -s /Users/yourname/.php /usr/alternatives/php

Add aliases to .zshrc:

# Switch PHP
alias php56="ln -sf /usr/local/php5/bin/php /Users/yourname/.php && php -v"
alias php72="ln -sf /usr/local/Cellar/php/7.2.8/bin/php /Users/yourname/.php && php -v"

And edit $PATH:

export PATH="/usr/alternatives:$PATH"

Switch between versions

Use aliases:

php72
php56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment