Created
August 10, 2017 15:45
-
-
Save christianhanne/dbed3f9848908774ad2eb4cc34f5b2fe to your computer and use it in GitHub Desktop.
Change PHP version in terminal using MAMP.
This file contains 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
#!/bin/bash | |
PHP_DIR="/Applications/MAMP/bin/php/" | |
BIN_DIR="/usr/local/bin/" | |
function use_version { | |
PHP_VERSION_PATH="${PHP_DIR}php${1}/bin/" | |
if [ ! -d "$PHP_VERSION_PATH" ]; then | |
echo "PHP version $1 does not exist." | |
exit 1 | |
fi | |
# Ask for permissions right away | |
sudo -v | |
# Symlink all relevant binaries. | |
sudo rm -f "${BIN_DIR}php" "${BIN_DIR}pear" "${BIN_DIR}pecl" | |
sudo ln -s "${PHP_VERSION_PATH}php" "${BIN_DIR}php" | |
sudo ln -s "${PHP_VERSION_PATH}pear" "${BIN_DIR}pear" | |
sudo ln -s "${PHP_VERSION_PATH}pecl" "${BIN_DIR}pecl" | |
# Output the now active php version. | |
echo "Now using the following php version:" | |
. ~/.bash_profile | |
php -v | |
exit | |
} | |
function list_versions { | |
for f in $(ls $PHP_DIR | grep php) | |
do | |
echo ${f#"php"} | |
done | |
} | |
case "$1" in | |
use) | |
use_version $2 | |
;; | |
list) | |
list_versions | |
;; | |
*) | |
echo "Usage: $0 {list|use version}" | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment