Permissions problem with IM 6.5.3 on Mac

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
kakman

Permissions problem with IM 6.5.3 on Mac

Post by kakman »

Hi all,

Apologies for the long first post. I've been using Imagemagick now for a total of three or four days and through a bunch of trial and error have it doing almost everything I need. Unfortunately I've struck a problem after upgrading to 6.5.3 and 10.6 on Mac OS X*. I had success with the following line (in IM 6.2.x/10.5) performing a fairly agricultural crop of an image submitted from a PHP form.

Code: Select all

system("exec 2>&1; $im_path/convert -colorspace RGB $filename2 -resize '575x575^' -gravity center -extent '575x393' $filename2");
Upon installing the new version this now results in an error; dyld: Library not loaded: /ImageMagick-6.5.3/lib/libMagickCore.2.dylib Referenced from: /usr/local/Imagemagick/ImageMagick-6.5.3/bin/convert Reason: image not found sh: line 1: 1090 Trace/BPT trap.

The error appeared to indicate an issue finding the file so I echoed the passed command and copied the resulting string into Terminal where it threw a Permissions Denied error. If I change the image permissions to 0777 the file can now be processed successfully via Terminal. I added a chmod 0777 function to the script but it still fails when I try and run it through PHP. Owner of the file is _www. The only thing I can think of is the Terminal and PHP are running as different users and that's causing the problem (keep in mind I'm not a CLI person per se so this is purely speculation on my part).

I've searched the forums, googled everything you can imagine and spent hours trying everything I can think of. I've not eliminated this being an issue with OSX but the fact it does run from the Terminal tends to indicate a problem with the user running PHP. When searching the forums I did see some mention of changing permission of the sites directory and manually adding virtual hosts but I'm reluctant to do anything manually which Apple could overwrite with an update. I'm not sure whether it's possible to forcibly run IM or the System call as a particular user but I'd be happy to try if someone could point me in the right direction.

Any other assistance or suggestions would be greatly appreciated.

'k

* I upgraded to 10.6 and 6.5.3 as our new XServes will be running this by default and it seemed logical to test on what will be required.
vishvesh

Re: Permissions problem with IM 6.5.3 on Mac

Post by vishvesh »

try running your script by call sudo script_path. That should solve all the permission issues
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Permissions problem with IM 6.5.3 on Mac

Post by anthony »

Sounds to me more like your ImageMagick was not installed properly, or in a unusual way.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
kakman

Re: Permissions problem with IM 6.5.3 on Mac

Post by kakman »

anthony wrote:Sounds to me more like your ImageMagick was not installed properly, or in a unusual way.
Thanks for the response. I've just done a reinstall, this time using the i386 rather than Universal binary. Instead of /usr/local/Imagemagick where I'd previously installed I used /Librarty/Imagemagick just to see if it made any difference. Install went fine and the CLI seems to be working as expected (it has processed every test I've done). Unfortunately I'm still getting permission errors from a System(exec); call in PHP. A few of the OSX forums have messages saying people are having problems with sudo and permissions so I'm not discounting the OS as the problem, but it's becoming increasingly infuriating :( .

It remains that this command runs fine in the Terminal but fails when called from the PHP script;

Code: Select all

/Library/Imagemagick/ImageMagick-6.5.3/bin/convert -colorspace RGB /Library/WebServer/Documents/td/images/2009/3_9_09/1251957688_012.jpg -resize '575x575^' -gravity center -extent '575x393' /Library/WebServer/Documents/td/images/2009/3_9_09/1251957688_012.jpg 
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Permissions problem with IM 6.5.3 on Mac

Post by anthony »

More than likely the dyld_library_path is different under PHP than from the command line. That is your running environment. First try convert -version or equivelent type test.

http://www.imagemagick.org/Usage/api/#php
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
kakman

Re: Permissions problem with IM 6.5.3 on Mac

Post by kakman »

anthony wrote:More than likely the dyld_library_path is different under PHP than from the command line. That is your running environment. First try convert -version or equivelent type test.
OK, that's interesting, convert -version via the CLI returns

Code: Select all

$ /Library/Imagemagick/ImageMagick-6.5.3/bin/convert -version
Version: ImageMagick 6.5.3-7 2009-06-14 Q16 OpenMP http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
but the same command from PHP returns the

Code: Select all

dyld: Library not loaded: /ImageMagick-6.5.3/lib/libMagickCore.2.dylib Referenced from: /Library/Imagemagick/ImageMagick-6.5.3/bin/convert Reason: image not found sh: line 1: 2716 Trace/BPT trap 
So I'm afraid I have to now ask, where/how would I define the path to the dyld_library_path for PHP?

FWIW, another things I've discovered from experimenting a little is that I can execute the PHP as a shell script and it works (which I guess is not surprising given the revelations from the tests I just did). It does mean though that if necessary, I can develop a long winded kind of workaround).

Thanks again for your help (and patience)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Permissions problem with IM 6.5.3 on Mac

Post by fmw42 »

why not just install from source rather than binary (and do it manually rather than with FINK or MacPorts)
http://www.imagemagick.org/download/www ... .html#unix

I don't know if this will help, but here are my old experiences with Mac installs from binary and source:

viewtopic.php?f=1&t=10442

also another possibly relevant post not too long ago
viewtopic.php?f=3&t=14466
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Permissions problem with IM 6.5.3 on Mac

Post by anthony »

kakman wrote:but the same command from PHP returns the

Code: Select all

dyld: Library not loaded: /ImageMagick-6.5.3/lib/libMagickCore.2.dylib Referenced from: /Library/Imagemagick/ImageMagick-6.5.3/bin/convert Reason: image not found sh: line 1: 2716 Trace/BPT trap 
Now that is interesting. The command is in
/Library/Imagemagick/ImageMagick-6.5.3/bin/convert
but it is looking for the library in
/ImageMagick-6.5.3/lib/libMagickCore.2.dylib

I would say the DYLD_LIBRARY_PATH environment variable is wrong.

type "echo $DYLD_LIBRARY_PATH" on the command line, and then do the same in PHP. you will probably find they are different. You may also like to look at other environment variables too, such as PATH. The command "env" will list all the currently set environment variables.

Remember a login has a very different setup and configuration path, that a web server, and it is this differences that causes these types of problems.


Rebuilding IM using methods given by Fred, can also help with this, as commands has a library path (called a "rpath") compiled into the program. This can make the command independant of the DYLD_LIBRARY_PATH environment.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
kakman

Re: Permissions problem with IM 6.5.3 on Mac

Post by kakman »

anthony wrote: Now that is interesting. The command is in
/Library/Imagemagick/ImageMagick-6.5.3/bin/convert
but it is looking for the library in
/ImageMagick-6.5.3/lib/libMagickCore.2.dylib

I would say the DYLD_LIBRARY_PATH environment variable is wrong.

type "echo $DYLD_LIBRARY_PATH" on the command line, and then do the same in PHP. you will probably find they are different. You may also like to look at other environment variables too, such as PATH. The command "env" will list all the currently set environment variables.
OK, it's working :D - but it might be a bit bodgy :(

Terminal returned /Library/IM.. from $DYLD_LIBRARY_PATH. I tried this with PHP it returned no result. Not sure what that means but could be the source of the problem. In phpinfo there is this entry but I'm not sure if this is pertinent; _ENV["PATH"] /usr/bin:/bin:/usr/sbin:/sbin.

FWIW, my .profile file has this which seems to be correct based on the binary install instructions:

export MAGICK_HOME="/Library/Imagemagick/ImageMagick-6.5.3"
export PATH=$MAGICK_HOME/bin:$PATH
export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib"

Anyway, the simple fix was creating a symbolic link to the /Library/Imagemagick folder. Whilst this is probably not considered a 'proper' fix, I'm happy that it works in a development scenario - I'll need to see what to do with the server as I'd like it to be correct. I may well build from source as per Fred's advice.

Just want to say thanks very much to all who responded - particularly you Anthony. There's a few forums around which are less than helpful but I've learnt a lot from here in just a few days, not just from this thread but from reading through a lot of older stuff as well. This IM is super cool.

Thanks again folks.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Permissions problem with IM 6.5.3 on Mac

Post by anthony »

Thats the problem. in PHP the MAGICK_HOME environment variable is unset!

Try this from PHP...

Code: Select all

   env MAGICK_HOME='/Library/Imagemagick/ImageMagick-6.5.3' \
       convert -version
If that fails try this.

Code: Select all

   env MAGICK_HOME='/Library/Imagemagick/ImageMagick-6.5.3' \
         DYLD_LIBRARY_PATH='/Library/Imagemagick/ImageMagick-6.5.3/lib' \
       convert -version
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply