Resolved: MAMP Php can't exec ('conver

2019-03-09 11:41发布

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.

6条回答
SAY GOODBYE
2楼-- · 2019-03-09 11:47

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:

DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH

Done.

查看更多
ら.Afraid
3楼-- · 2019-03-09 11:59
sudo ln -s /usr/local/bin/convert /usr/bin/convert
查看更多
【Aperson】
4楼-- · 2019-03-09 12:00

Verify that convert in is the server's PATH environment variable. Or just specify the full path:

exec('/usr/local/bin/convert -version');
查看更多
女痞
5楼-- · 2019-03-09 12:03

instead of just exec("convert .... "); use a full path. you can get it by typing the terminal

type convert

you should get something like: convert is hashed (/opt/local/bin/convert)

so now use:

exec("/opt/local/bin/convert .... ");

[credits to @Nikki]

after that comment out

DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH" export DYLD_LIBRARY_PATH

in /Applications/MAMP/Library/bin/envvars

查看更多
迷人小祖宗
6楼-- · 2019-03-09 12:06

Simply use exec("PATH=\$PATH:/usr/local/bin; convert file.pdf file.png"); It will add convert to PATH on runtime.

查看更多
对你真心纯属浪费
7楼-- · 2019-03-09 12:08

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('convert -version', $output);
var_dump($output); // it is an array which filled with every line of output from the command
查看更多
登录 后发表回答