我在Mac OSx上,使用MAMP。当我直接在终端中运行git命令时,它们按预期工作,没有任何错误。但我正在php中编写一个脚本,用于运行一些git命令,我得到了以下错误:
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] =>
)
搜索会给出一组结果(例如,这里),解释这是一个OSx/MAMP问题,修复方法是将export DYLD_LIBRARY_PATH=/usr/lib/
添加到.bash_profile
中。但正如我所说,我在终端没有问题,我只在从php的exec()
调用git时得到错误。我确实将DYLD_LIBRARY_PATH=...
添加到了我的bash_profile
中,这没有什么区别。
调用exec()
是否不会调用我的bash_profile
,即使Apache设置为以我的普通用户身份运行?
如果这有效,那么我认为exec没有调用您的bash_profile。
exec('export DYLD_LIBRARY_PATH=/usr/lib cd /my/path/here/ 2>&1 && git init 2>&1', $out, $return);