Macport allows you now to manage different php versions. Switching between them is no more a splinter.

# bash
#!/bin/bash
# Start the Apache and Mysql server
Start()
{
  sudo /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper start
  sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper start
}
# Stop the Apache and Mysql server
Stop()
{
  sudo /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper stop
  sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper stop
}
# Stop and Start the servers
Restart()
{
  Stop
  Start
}
# Graceful
Reload()
{
  [ -r /opt/local/apache2/logs/httpd.pid ] && sudo /opt/local/apache2/bin/apachectl graceful > /dev/null
}
# Returns the apache vhosts list
Hosts()
{
  sudo /opt/local/apache2/bin/apachectl -S
}
# Returns the apache modules loaded
Modules()
{
  sudo /opt/local/apache2/bin/apachectl -M
}
# Pass raw parameters to the apachectl binary
Raw()
{
  sudo /opt/local/apache2/bin/apachectl $1
}
# Change the current php version
Switch()
{
  Stop
  sudo port select --set php $1
  sudo ln -sf "/opt/local/apache2/conf/httpd.${1}.conf" /opt/local/apache2/conf/httpd.conf
  Start
  php -v
}
Run()
{
    case $1 in
      start     ) Start     ;;
      stop      ) Stop      ;;
      reload    ) Reload    ;;
      restart   ) Restart   ;;
      modules   ) Modules   ;;
      hosts     ) Hosts     ;;
      raw       ) Raw $2    ;;
      switch    ) Switch $2 ;;
      * ) echo "$0: unknown argument: $1";;
    esac  
}

Run $1 $2

A more recent version is maintained by this gist:

Created on 05-08-2009 by Eric le bihen

comments powered by Disqus