2014-09-30 92 views
0

我在Mac OSx上使用MAMP。當我在終端中直接運行git命令時,它們按預期工作,沒有錯誤。但我寫在PHP腳本,這意味着運行一些Git命令,和我收到以下錯誤:從PHP腳本中調用git命令返回「dyld:lazy symbol binding failed」

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

回報:

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] => )

一個搜索給出一堆的結果(例如here)解釋了這是OSx/MAMP問題,修復方法是將export DYLD_LIBRARY_PATH=/usr/lib/添加到您的.bash_profile。但正如我所說,我沒有從終端問題,我只從php的exec()調用git時出現錯誤。我確實將DYLD_LIBRARY_PATH=...添加到了我的bash_profile,並沒有什麼區別。

是否調用exec()不會調用我的bash_profile,即使Apache設置爲以普通用戶身份運行?

回答

0

如果這有效,那麼我會假定exec不會調用您的bash_profile。

exec('export DYLD_LIBRARY_PATH=/usr/lib cd /my/path/here/ 2>&1 && git init 2>&1', $out, $return); 
+0

這樣做的工作,我實際上在發佈之前嘗試過。但是我正在編寫的腳本將會被推送到我的團隊的版本控制中,並分發給其他開發人員。我不認爲我可以在腳本中包含「非便攜式」硬編碼的內容。 – shauno 2014-09-30 06:51:11

+0

你可能有這個http://stackoverflow.com/questions/3428647/php-exec-path-variable-missing-elements – 2014-09-30 15:07:22

+0

感謝您的鏈接。如果我運行'echo shell_exec(「echo $ 0」);'我得到'sh',而不是'bash'。所以看來PHP甚至不會調用bash。我想我的問題變成了如何讓PHP在運行shell命令時使用bash,**或者**我如何獲得bourne shell來更改它的DYLD_LIBRARY_PATH? – shauno 2014-09-30 19:51:53