Skip to content

Instantly share code, notes, and snippets.

@thsutton
Created October 7, 2010 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thsutton/614535 to your computer and use it in GitHub Desktop.
Save thsutton/614535 to your computer and use it in GitHub Desktop.

A simple PHP wrapper for MAMP

MAMP is a pretty crappy environment, but it beats the shit out of building a decent environment myself and is marginally more convenient than working on a Linux VM. This little script makes it more useful (for me) by providing a fake php command in the $MAMP/Library/bin directory which calls the real php from the version you've configured MAMP to use.

Just put the accompanying script in the $MAMP/Library/bin directory and make it executable, then make sure that $MAMP/Library/bin is in your $PATH before /usr/bin (and any other directory containing an executable called php).

Then any invocation of php will be executed with the correct version (as far as MAMP cares, anyway!)

Future improvements include using the "next" php in $PATH if MAMP is not running.

#!/usr/bin/env bash
#
# Run the PHP executable for whichever version is configured in MAMP.
#
# The script assumes that it's put in $MAMP/Library/bin, as that's what I
# have in my $PATH ($MAMP/bin being full of reasonably pointless scripts and
# sub-directories).
#
root="`dirname $0`/../.."
conf="$root/conf/apache/httpd.conf"
version=`cat "$conf" | grep -i loadmodule | grep -i php5_module | awk '{ print $3 }' | cut -d/ -f2`
PHP="$root/bin/$version/bin/php"
$PHP $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment