我在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设置为以普通用户身份运行?
这样做的工作,我实际上在发布之前尝试过。但是我正在编写的脚本将会被推送到我的团队的版本控制中,并分发给其他开发人员。我不认为我可以在脚本中包含“非便携式”硬编码的内容。 – shauno 2014-09-30 06:51:11
你可能有这个http://stackoverflow.com/questions/3428647/php-exec-path-variable-missing-elements – 2014-09-30 15:07:22
感谢您的链接。如果我运行'echo shell_exec(“echo $ 0”);'我得到'sh',而不是'bash'。所以看来PHP甚至不会调用bash。我想我的问题变成了如何让PHP在运行shell命令时使用bash,**或者**我如何获得bourne shell来更改它的DYLD_LIBRARY_PATH? – shauno 2014-09-30 19:51:53