8
votes

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?

1
PHP is executing a different copy of that library, somehow. Check your paths, make sure you don't have conflicting versions.Brad
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
@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
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
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

1 Answers

18
votes

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