Skip to content

Instantly share code, notes, and snippets.

@nojimage
Created December 8, 2010 11:36
Show Gist options
  • Save nojimage/733166 to your computer and use it in GitHub Desktop.
Save nojimage/733166 to your computer and use it in GitHub Desktop.
php switch (php5.2 <-> php5.3) for macports
#!/usr/bin/env bash
##
# php switch (php5.2 <-> php5.3) for macports
#
# @original http://mark-story.com/posts/view/updating-to-php5-3-with-macports
#
PORT_BIN=/opt/local/bin/port
APACHECTL_BIN=/opt/local/apache2/bin/apachectl
function get_ports_installed_version(){
echo `${PORT_BIN} installed ${1} | tail -n 1 | awk '/${1}/ {print $2}'`
}
function activate_php5_subpackages(){
for name in `${PORT_BIN} installed php5-* | grep -e '@5.3' | grep -v '(active)' | awk '{print $1}'`;do
local LAST_VERSION
LAST_VERSION=`get_ports_installed_version ${name}`
${PORT_BIN} activate ${name} ${LAST_VERSION}
done
}
function deactivate_php5_subpackages(){
for name in `${PORT_BIN} installed php5-* | grep -e '@5.3' | grep -e '(active)' | awk '{print $1}'`;do
local LAST_VERSION
LAST_VERSION=`get_ports_installed_version ${name}`
${PORT_BIN} deactivate ${name} ${LAST_VERSION}
done
}
PHP52_VERSION=`get_ports_installed_version "php52"`
PHP53_VERSION=`get_ports_installed_version "php5"`
## main
${APACHECTL_BIN} stop
case "$1" in
'php52')
${PORT_BIN} deactivate php5
deactivate_php5_subpackages
${PORT_BIN} activate php52 $PHP52_VERSION
cp -f /opt/local/etc/php5/php52.ini /opt/local/etc/php5/php.ini
;;
'php5')
${PORT_BIN} deactivate php52
${PORT_BIN} activate php5 $PHP53_VERSION
activate_php5_subpackages
cp -f /opt/local/etc/php5/php53.ini /opt/local/etc/php5/php.ini
;;
esac
${APACHECTL_BIN} start
@nojimage
Copy link
Author

nojimage commented Dec 8, 2010

バージョン切り替えはCGI版でやるのが楽だよなと思いつつ、モジュール版での切り替え用sh

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