Merge "Improve detection of php binary."
authorAaron Schulz <aschulz@wikimedia.org>
Sat, 4 Aug 2012 08:45:49 +0000 (08:45 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 4 Aug 2012 08:45:49 +0000 (08:45 +0000)
maintenance/dev/includes/php.sh

index 3021b93..f5b712a 100644 (file)
@@ -1,12 +1,14 @@
 # Include-able script to determine the location of our php if any
+# We search for a environment var called PHP, native php,
+# a local copy, home directory location used by installphp.sh
+# and previous home directory location
+# The binary path is returned in $PHP if any
 
-if [ -d "$DEV/php" -a -x "$DEV/php/bin/php" ]; then
-       # Quick local copy
-       PHP="$DEV/php/bin/php"
-elif [ -d "$HOME/.mediawiki/php" -a -x "$HOME/.mediawiki/php/bin/php" ]; then
-       # Previous home directory location to install php in
-       PHP="$HOME/.mediawiki/php/bin/php"
-elif [ -d "$HOME/.mwphp" -a -x "$HOME/.mwphp/bin/php" ]; then
-       # Previous home directory location to install php in
-       PHP="$HOME/.mwphp/bin/php"
-fi
+for binary in $PHP `which php || true` "$DEV/php/bin/php" "$HOME/.mediawiki/php/bin/php" "$HOME/.mwphp/bin/php" ]; do
+       if [ -x "$binary" ]; then
+               if "$binary" -r 'die(!version_compare(PHP_VERSION, "5.4", ">="));'; then
+                       PHP="$binary"
+                       break
+               fi
+       fi
+done