[SOLVED] Cannot load PDF with PHP-FPM

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
josh4trunks
Posts: 3
Joined: 2014-07-21T22:38:19-07:00
Authentication code: 6789

[SOLVED] Cannot load PDF with PHP-FPM

Post by josh4trunks »

I can't seem to get PDFs to load when running a script using PHP-FPM. Any help would be greatly appreciated. Thanks,

SPECIFICATIONS
OS ~ FreeBSD 10 64bit
PHP ~ 5.5.14
ImageMagick ~ 6.8.9.4
Pecl-Imagick ~ 3.1.2

TEST SCRIPT

Code: Select all

<?php
$path = '/tmp/in.pdf';
$pdf = new Imagick($path);
$pdf->setImageFormat('jpg');
$pdf->writeImage('/tmp/out.jpg');
?>
ERROR

Code: Select all

Fatal error: Uncaught exception 'ImagickException' with message 'Unable to read the file: /tmp/in.pdf' in /usr/local/www/test.php:3 Stack trace: #0 /usr/local/www/test.php(3): Imagick->__construct('/tmp/in.pdf') #1 {main} thrown in /usr/local/www/test.php on line 3
TEST SCENARIOS
* PDF to JPG using PHP on the CommandLine > works
* PDF to JPG using PHP-FPM from browser > doesn't work (error above)
* JPG to PDF using PHP-FPM from browser > works
Last edited by josh4trunks on 2014-07-22T00:38:48-07:00, edited 1 time in total.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Cannot load PDF with PHP-FPM

Post by dlemstra »

Did you also install Ghostscript?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
josh4trunks
Posts: 3
Joined: 2014-07-21T22:38:19-07:00
Authentication code: 6789

Re: Cannot load PDF with PHP-FPM

Post by josh4trunks »

dlemstra wrote:Did you also install Ghostscript?
I have "ghostscript9-nox11-9.06" installed which is a dependency of Imagemagick.

Maybe with PHP-FPM (which uses the 'www' user with a limited shell) ghostscript isn't accessible? But it is accessible when I run the script from the commandline?

EDIT
Does Imagick from PHP call 'gs' directly? If so, that's probably my issue, 'gs' is installed in /usr/local/bin, but my 'www' user doesn't include that location in it's path.
See http://php.net/manual/en/function.shell-exec.php#78506
josh4trunks
Posts: 3
Joined: 2014-07-21T22:38:19-07:00
Authentication code: 6789

Re: [SOLVED] Cannot load PDF with PHP-FPM

Post by josh4trunks »

SOLVED
Thanks for leading me in the right direction!

All I did was add this to my php-fpm.conf and conversion of PDF's now work =]

Code: Select all

env[PATH] = /usr/local/bin:/usr/bin:/bin
ajm0824
Posts: 1
Joined: 2016-03-31T18:59:49-07:00
Authentication code: 1151

Re: [SOLVED] Cannot load PDF with PHP-FPM

Post by ajm0824 »

I too am having a similar problem but this fix is not working for me. Can someone please point in the right direction?

I'm currently exploring file permission issues, but changed file and folder permissions to 0755 w/ same result


TEST SCRIPT

Code: Select all

<?php
$image = new Imagick('images/test.pdf');
$image->thumbnailImage(300, 0);
echo '<img src="data:image/png;base64,' .  base64_encode($image->getimageblob())  . '" />';
 ?>

ERROR
- ImagickException: Failed to read the file


NOTE THE FOLLOWING WORKS ON COMMAND LINE

Code: Select all

convert test.pdf test.jpeg


SPECIFICATIONS
Mac OSX
PHP 5.6 installed via homebrew
ghostscript installed via homebrew
ImageMagick installed via homebrew w/ ghostscript dependency



TEST SCENARIOS
* PDF to JPG using PHP on the CommandLine > works
* PDF to JPG using PHP from browser > doesn't work (error above)
Post Reply