Over the weekend, I updated my local Drupal development environment to use WAMP instead of XAMPP, simply because WAMP lets you switch between versions of PHP. Unfortunately WAMP doesn't set the PATH to PHP so in your CLI you need to update PATH manually either in your environment variables (Windowz) or in .bashrc (Cygwin/*nix). I searched for a way to automate this and couldn't find anything so I wrote this small snippet to do it automatically.

Here's how it works: In WAMP when you change to a different version of PHP, it updates the wampmanager.conf file with the newly selected version of PHP. This snippet, when placed in .bashrc, searches the wampmanager.conf for the selected PHP version and adds it to PATH. It's very simple, here goes:

# Where is the wampmanager.conf file located?
WAMPCONF="C:\wamp\wampmanager.conf"
# Where is wamp installed? This is specific to cygwin
WAMPDIR="/cygdrive/c/wamp"
 
# Require the wampmanager file
if  ! [ -f "${WAMPCONF}" ] ; then
  echo "$WAMPCONF is not valid";
  exit 1
else
  # Grep the current version of PHP from the wampmanager file.
  # I'm sure there is a more elegant way to do this
  PHPVERSION="$(grep -F -m 1 'phpVersion =' $WAMPCONF)";
  PHPVERSION="${PHPVERSION#*\"}";
  PHPVERSION="${PHPVERSION%\"*}";
  # Set your path
  PATH="$WAMPDIR/bin/php/php$PHPVERSION:${PATH}"
fi

This needs to be placed in either .bashrc or .bash_profile. You also need to remove any environment variables you've added in Windows that points to PHP.

Comments

Add new comment