0

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)
directory
  • 3,093
  • 8
  • 45
  • 85
  • the default user for php/apache is "www-data". you can try this: http://askubuntu.com/questions/204159/add-path-to-path-environment-variable-for-www-data – Kevin Jan 14 '16 at 14:46
  • can you update your question to include the calls to `shell_exec`? – Alex Andrei Jan 14 '16 at 14:49
  • Having this issue in 2020 and finding no answers :/ for whatever reason editing /etc/environment or /etc/apache2/envvars isn't working for me – Shardj Jun 30 '20 at 11:16

0 Answers0