Skip to content

Instantly share code, notes, and snippets.

@renatomefi
Last active December 11, 2018 14:08
Show Gist options
  • Save renatomefi/e71eb87ad83a8d16bf0e to your computer and use it in GitHub Desktop.
Save renatomefi/e71eb87ad83a8d16bf0e to your computer and use it in GitHub Desktop.
Alternatives install for PHP
#!/bin/bash
# ------------------------------------------------------------------
# [Author] Renato Mefi <gh@mefi.in>
# https://github.com/renatomefi
#
# [Desc] Configure alternatives for PHP Installations
# Very usefull when you are building your PHP and don't want to use
# more sofsticated softwares like 'phpbrew', 'php-build', 'php-env' ...
#
# [Usage] ./php-alternatives-install.sh /path/for/php/installation 200
#
# [I.E.] ./php-alternatives-install.sh /opt/php/php-5.6.8 200
# ./php-alternatives-install.sh /opt/php/php-7.0.0-dev 1
#
# $sudo alternatives --config php
# There are 2 programs which provide 'php'.
#
# Selection Command
# -----------------------------------------------
# * 1 /opt/php/php-5.6.8/bin/php
# + 2 /opt/php/php-7.0.0-dev/bin/php
#
# Enter to keep the current selection[+], or type selection number: 2
#
# [Download] https://gist.github.com/renatomefidf/e71eb87ad83a8d16bf0e/download
#
LINKDIR=/usr/bin
PHPPATH=$1
PHPBIN=$PHPPATH/bin
[ -z $2 ] && PRIORITY=20000 || PRIORITY=$2
echo "Installing alternatives for PHP at $LINKDIR from $PHPBIN"
echo "With priority of $PRIORITY";
sudo alternatives --install $LINKDIR/php php $PHPBIN/php $PRIORITY \
--slave $LINKDIR/php-cgi php-cgi $PHPBIN/php-cgi \
--slave $LINKDIR/php-config php-config $PHPBIN/php-config \
--slave $LINKDIR/phpize phpize $PHPBIN/phpize \
--slave $LINKDIR/phar.phar phar.phar $PHPBIN/phar.phar \
--slave $LINKDIR/phar phar $PHPBIN/phar \
--slave $LINKDIR/pecl pecl $PHPBIN/pecl \
--slave $LINKDIR/pear pear $PHPBIN/pear \
--slave $LINKDIR/peardev peardev $PHPBIN/peardev
echo "Current alternatives for PHP"
alternatives --display php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment