0

I'm on Mac OSx, using MAMP. When I run git commands directly in the terminal, they work as expected with no errors. But I'm writing a script in php, that is meant to run some git commands, and I am getting the following error:

exec('cd /my/path/here/ 2>&1 && git init 2>&1', $out, $return);

returns:

Array ( [0] => dyld: lazy symbol binding failed: Symbol not found: _iconv_open [1] => Referenced from: /Applications/Xcode.app/Contents/Developer/usr/bin/git [2] => Expected in: /Applications/MAMP/Library/lib/libiconv.2.dylib [3] => [4] => dyld: Symbol not found: _iconv_open [5] => Referenced from: /Applications/Xcode.app/Contents/Developer/usr/bin/git [6] => Expected in: /Applications/MAMP/Library/lib/libiconv.2.dylib [7] => )

A search gives a bunch of results (here for example) explaining how this is an OSx / MAMP issue, with the fix being to add export DYLD_LIBRARY_PATH=/usr/lib/ to your .bash_profile. But as I said, I do not have a problem from the terminal, I only get the error when calling git from php's exec(). I did add the DYLD_LIBRARY_PATH=... to my bash_profile, and it made no difference.

Does calling exec() not invoke my bash_profile, even if Apache is set to run as my normal user?

Community
  • 1
  • 1
shauno
  • 121
  • 2
  • 10

1 Answers1

0

If this works, then I would presume exec is not invoking your bash_profile.

exec('export DYLD_LIBRARY_PATH=/usr/lib cd /my/path/here/ 2>&1 && git init 2>&1', $out, $return);
Andrew C
  • 13,845
  • 6
  • 50
  • 57
  • That does work, I actually tried it before posting. But the script I am writing is going to be pushed into my team's version control, and distributed to the other devs. I don't think I can have something that 'non-portable' hard-coded into the script. – shauno Sep 30 '14 at 06:51
  • The you likely have a dupe of this http://stackoverflow.com/questions/3428647/php-exec-path-variable-missing-elements – Andrew C Sep 30 '14 at 15:07
  • Thanks for the link. If I run `echo shell_exec("echo $0");` I get `sh`, not `bash`. So it seems PHP isn't even invoking bash. I guess my question becomes how do I get php to use bash when running shell commands, **or** how do I get bourne shell to change its DYLD_LIBRARY_PATH? – shauno Sep 30 '14 at 19:51