0

I 'm despair...

I installed Ghostscript on Mac OS X Yosemite via Homebrew. Ghostscript works well over the shell, but it doesn't work, if it is executed via PHP.

$gs = '/usr/local/opt/ghostscript/bin/gs';

// Count PDF
$shell = $gs . ' -q    -dNODISPLAY    -c "(' . $pdf . ') (r) file runpdfbegin pdfpagecount = quit" 2>&1';
$result =  shell_exec($shell);

// Execution
$shell = $gs . ' -dNumRenderingThreads=4 -dNOPAUSE -sDEVICE=jpeg -dFirstPage=1 -dLastPage=1 -sOutputFile="' . $filePathThumb . '" -dJPEGQ=100 -r300 -q "' . $pdf . '" -c quit 2>&1';
$result =  shell_exec($shell);

The output of $result is:

dyld: Library not loaded: /usr/local/lib/libtiff.5.dylib
Referenced from: /usr/local/opt/ghostscript/bin/gs
Reason: Incompatible library version: gs requires version 8.0.0 or later, but libtiff.5.dylib      provides version 7.0.0

If i execute the same command on the shell it works...

I tired so many things in the last days, but i still struggling.

I reinstalled gs and imagemagick, i removed the symlinks, runned brew doctor, tried some other libtiff.5.dyslib files.

My environment:

  • Yosemite
  • PHP Version 5.5.13
  • Zend Server Version: 7.0.0
  • Imagemagick Version 6.8.9-8 (installed via brew)
  • Ghostscript Version 9.15 (installed via brew)
iron91
  • 11
  • 1

1 Answers1

0

Clearly you are using a version of Ghostscript with shared libraries (which is why it wants libtiff.dylib). We don't recommend that, and you could avoid it by downloading the Ghostscript sources and building them yourself. This is a 'some assembly required' project, as you will need things like gcc installed. However I managed it and I'm far from a Mac expert.

However, this will probably just move you on the real underlying problem which is that your PHP environment does not match your shell. In this case the PATH environment variable is probably different, which means that the shell can find the dynamic library, but the PHP can't.

Since Ghostscript can use certain environment variables, you need to make sure that the environment that the PHP script executes in is the same as the one the shell uses.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • This link may help http://stackoverflow.com/questions/11256008/setting-environment-variables-in-mamp – KenS Nov 27 '14 at 13:37