8

I'm having a bizarre problem with php 5.3.6 and ImageMagick (command line) using MAMP (and Macports too..I tried both) on OS X.

When I run the identify command from the CLI, it works fine. But when I run the exact same command using exec(), it returns a value code of 5 and in the apache error logs I have:

dyld: Library not loaded: /opt/local/lib/libfreetype.6.dylib
Referenced from: /opt/local/bin/identify Reason: Incompatible library version: identify requires version 14.0.0 or later, but libfreetype.6.dylib provides version 13.0.0

E.g. The cli command is: /opt/local/bin/identify /Users/leonardteo/Documents/1.jpg

This works just fine when executed from the command line. When executed from PHP:

exec("/opt/local/bin/identify /Users/leonardteo/Documents/1.jpg", $output, $return);

$return is 5

$output is nothing

Checking the apache logs gives the above issue with libfreetype.

I installed ImageMagick using Macports. I've also tried a manual build from source and running identify from /usr/local/bin/identify and I get the same result. I have also tried running PHP from Macports instead of MAMP and I get the same result.

Could someone please help shed light on this?

Brad
  • 159,648
  • 54
  • 349
  • 530
Leonard Teo
  • 1,238
  • 1
  • 17
  • 28
  • PHP is executing a different copy of that library, somehow. Check your paths, make sure you don't have conflicting versions. – Brad Oct 18 '11 at 19:06
  • CLI php usually has a seperate .ini file from SAPI php, so the two .ini's can potentially be loading different versions of the library. – Marc B Oct 18 '11 at 19:08
  • @Marc B: This isn't a problem between running php on cli and php through Apache. It's between an actual cli command on the bash shell and executing the exact same command through PHP. – Leonard Teo Oct 18 '11 at 19:15
  • Hmm. d'oh... right. Was imagick statically compiled into PHP? Could that it's got v14 internally, but you've installed v13 for the rest of the system. – Marc B Oct 18 '11 at 19:20
  • No no I'm not trying to run IM compiled into PHP. I'm trying to execute it as a command line tool from within PHP using exec(). I installed two versions of IM: one is using Macports (which gives me the libfreetype error but only in PHP) and another one from source in /usr/local/bin (which also throws another error but again, only in PHP). – Leonard Teo Oct 18 '11 at 19:26
  • Oh my gosh. This is the answer: Edit this file: > /Applications/MAMP/Library/bin/envvars Comment out the following lines: > DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH" > export DYLD_LIBRARY_PATH Restart MAMP/Apache. And it works. – Leonard Teo Oct 18 '11 at 19:52

1 Answers1

18

Edit this file:

/Applications/MAMP/Library/bin/envvars

Comment out the following lines:

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

export DYLD_LIBRARY_PATH

Community
  • 1
  • 1
Leonard Teo
  • 1,238
  • 1
  • 17
  • 28
  • Nice, the other way would be to simply switch the server instance to XAMPP that works out of the box http://tekkie.flashbit.net/developer-tools/workaround-for-imagemagick-convert-returning-5 – Ain Tohvri Nov 26 '11 at 18:27
  • Thx a lot!!! It was trying for a couple of hours to find out the reason why it did not work. Fortunately StackOverflow and You, dear sir, saved my ass again ;) – maddob Mar 23 '13 at 13:41
  • On XAMPP, the path is `/Applications/XAMPP/bin/envvars`, and because I used homebrew, instead of commenting it out I swapped out `[...]/lib` with `/usr/local/lib`. – Morgan Delaney Oct 16 '15 at 21:38