已解决:安装 Homebrew ImageMagick 后,MAMP Php 无法执行(“转换”)
我在 Lion 上使用 Homebrew 安装了 Imagemagick,一切都很好,只是从 php 调用时它根本不起作用。控制台:
$ convert -version
Version: ImageMagick 6.7.1-1 2011-07-29 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP
$ which convert
/usr/local/bin/convert
PHP:
echo exec ('convert -version');
或 exec('转换-版本', $output); var_dump($输出);
不产生任何内容(或产生空数组)。
exec ('/usr/local/bin/convert') // works, but
exec ('which convert') // doesn't
我需要在本地进行测试,以确保我可以在生产环境中检测到转换。但我无法正确测试它。 PATH 已设置并且可以在终端中使用,但不能在 PHP 中使用。
已解决:
事实证明,要使 php 正常工作,convert
应该位于 /usr/bin/
中,所以这解决了它:
ln -s /usr/local/bin/convert /usr/bin/convert
更新
这是因为MAMP,这里是修复:http://firedevcom.tumblr.com/post/22791937644/fix-for-homebrew-imagemagick-and-mamp
打开 /Applications/MAMP/Library/bin/envvars
并注释掉以下几行:
DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH
完成。
I installed Imagemagick using Homebrew on Lion, everything is fine except that it doesn't work at all when being called from php. Console:
$ convert -version
Version: ImageMagick 6.7.1-1 2011-07-29 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP
$ which convert
/usr/local/bin/convert
PHP:
echo exec ('convert -version');
or
exec('convert -version', $output);
var_dump($output);
Produces nothing (or an empty array).
exec ('/usr/local/bin/convert') // works, but
exec ('which convert') // doesn't
I need to test this locally to make sure I can detect convert in production environment. But I can't properly test it. The PATH is set and it works in Terminal, but not from PHP.
Resolved:
Turns out, for php to work convert
should be in /usr/bin/
so this solved it:
ln -s /usr/local/bin/convert /usr/bin/convert
Update
It was becasue of MAMP, here is the fix: http://firedevcom.tumblr.com/post/22791937644/fix-for-homebrew-imagemagick-and-mamp
Open /Applications/MAMP/Library/bin/envvars
And comment out the following lines:
DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH
Done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在这里添加我自己的答案,以便您可以投票:
这是由 MAMP 引起的,这是修复方法: http://firedevcom.tumblr.com/post/22791937644/fix-for-homebrew-imagemagick-and-mamp
打开
/Applications/MAMP/Library/bin/envvars
并注释掉以下行:
完成。
Adding my own answer here so you can vote:
It was caused by MAMP, here is the fix: http://firedevcom.tumblr.com/post/22791937644/fix-for-homebrew-imagemagick-and-mamp
Open
/Applications/MAMP/Library/bin/envvars
And comment out the following lines:
Done.
验证convert in 是服务器的PATH 环境变量。或者只指定完整路径:
Verify that convert in is the server's PATH environment variable. Or just specify the full path:
exec
返回命令结果的最后一行,该行恰好是一个空字符串。如果你想获得输出,只需执行以下操作:
The
exec
returns the last line from the result of the command which happens to be an empty string.If you want to get the output, just do something like this:
只需使用
exec("PATH=\$PATH:/usr/local/bin; Convert file.pdf file.png");
它会在运行时将 Convert 添加到 PATH 。Simply use
exec("PATH=\$PATH:/usr/local/bin; convert file.pdf file.png");
It will add convert to PATH on runtime.而不仅仅是 exec("convert .... ");
使用完整路径。你可以通过在终端输入来获取它
你应该得到类似的东西:
转换是散列的(/opt/local/bin/convert),
所以现在使用:
[致谢 @Nikki]
在评论之后
在 /Applications/MAMP/Library/bin/envvars 中
instead of just exec("convert .... ");
use a full path. you can get it by typing the terminal
you should get something like:
convert is hashed (/opt/local/bin/convert)
so now use:
[credits to @Nikki]
after that comment out
in /Applications/MAMP/Library/bin/envvars