2

I have an apache web server under OSX and an installed and configured ImageMagick. If I try to execute some ImageMagick command from the terminal, it works fine, but if I try to do that with exec or shell_exec from PHP, it doesn't work.

That is what I do: I set the environment variable:

apache_setenv("PATH", "/etc/ImageMagick-6.8.1/bin:".apache_getenv("PATH"));

and try to execute some command:

exec('convert -version', $imgkOut);

the $imgkOut array is always empty.

I tried to set both paths: 'convert ...' and '/etc/ImageMagick-6.8.1/bin/convert ...' - nothing helps.

In the apache log file I found these errors:

sh: convert: command not found

for the first case, and this:

sh: /etc/ImageMagick-6.8.1/bin/convert: Permission denied

for the second.

What do I do wrong?

2 Answers 2

1
  1. did you see http://php.net/manual/en/book.imagick.php ?
  2. try install imagemagick from macports - http://www.macports.org/ports.php?by=name&substr=imagemagick
  3. check exec for convert (maybe file hasnt +x flag? so just chmod +x convert)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. I don't want to install Imagick and Macports. convert now has these rights: -rwxrwxr-x@ 1 xxx staff 10748 31 Dez 18:05 convert but it still doesn't work.
0

The errors you are getting imply that:

  1. The apache_setenv command is not working.
  2. The web user does not have permission to run the command.

If you do

    cd /etc/ImageMagick-6.8.1/bin
    chmod +x convert

and try again with the second version, where you supply the complete path, it should work.

6 Comments

thanks for the answer. I already set the rights, but still get the same error: /etc/ImageMagick-6.8.1/bin/convert: Permission denied
Can you run any shell commands from a php script or is it just the convert?
don't know then. It should work if it's executable for all. Unless there's something in the php.ini that stops it unless it's in the global path. Try adding the PATH globally (not just in your shell) and see what happens. (serverfault.com/questions/16355/how-to-set-global-path-on-os-x/…) (you might need a restart)
It seems to doesn't work... The PATH is now ...:/etc/ImageMagick-6.8.1/bin, but i get the same error: convert: command not found
have you got more than one version of convert? try 'which convert' and see what the path is. (I'm clutching at straws!)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.