I am getting problems when I am trying to use some system packages such as ImageMagick in my application through shell_exec.
If I define the path myself packages work fine. ImageMagick works but as it uses Ghostscript package it goes wrong on this moment because my php path variable misses a path. I am able to get the version of ImageMagick etc.
My PHP path variable contains (output through shell_exec):
/usr/bin:/bin:/usr/sbin:/sbin
My packages uses '/usr/local/bin' so I would like to add this path to the php variable which is used by shell_exec.
The output when I echo $PATH through the terminal directly is:
/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Then, when I run my php script by the terminal '$ php script.php' the job is done fine. When I run the script by shell_exec through my browser it fails. As I think this has all to do with the env PATH who isn't matching at the time GhostScript needs to execute her task.
I am searching to include '/usr/local/bin' or synchronize the whole path. Hopefully to get some advice in how to do this. Thank you
Update
php script:
var_dump(shell_exec('/usr/local/bin/gs -dNOPAUSE -sDEVICE=jpeg -r144 -sOutputFile=/www/sites/domain/public_html/test.jpg /www/sites/domain/public_html/test.pdf'));
error_log
GPL Ghostscript 9.18: **** Could not open the file '/www/sites/domain/public_html/test.jpg'.
GPL Ghostscript 9.18: Unrecoverable error, exit code 1
browser output
GPL Ghostscript 9.18 (2015-10-05)
Copyright (C) 2015 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 18.
Page 1
Error: /invalidfileaccess in --showpage--
Operand stack:
1 true
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1967 1 3 %oparray_pop 196'... (length=1044)