0

I'm going crazy with this...

I'm trying to execute electron-pdf to generate some PDFs from a PHP application (using Laravel) and PHP 7.0.23.

When running the app with "php artisan serve", which uses php-cli, running the following works fine and generates my PDF:

shell_exec("electron-pdf $inputURL $outputFile");

When serving the app though nginx (using php-fpm) this command does nothing.

So I went to debug this issue... I've tried to run shell_exec("node -v") but it didn't run when under php-fpm, so I've noticed that the PATH that php-fpm uses is not that of the user defined in the pool, so I've defined the env[PATH] variable and now php-fpm sees the correct path, the same path that php-cli uses.

Now if I call shell_exec("node -v") I see v8.4.0 in both cli and fpm. So I thought that all was fine! I then tried shell_exec("electron-pdf --version") and... it prints fine on cli but does nothing on fpm...

How can I debug this? What's happening? How can it be that php-cli and php-fpm, running as the same user, with the same path, have different behaviors?

Thanks a lot, if you need further info I'll edit the question accordingly since I don't have enough reputation to comment.

PS: chroot is disabled, secure mode is off, shell_exec is not in the disable_functions

  • Web servers clear environment variables before running CGI scripts to prevent outside environment variables from contaminating the current environment and to ensure consistent results on execution. You need to update the environment vars that nginx passes to php, to match the environment vars from php-cli. You could also use `shell_exec` to run a bash script and set the environment vars at the top of the script, then call electron-pdf. (Like /etc/crontab does) – bassxzero Sep 22 '17 at 17:32
  • @bassxzero thanks for your help! I've tried to add ALL env vars shown in ```php --info``` and setting ```clear_env = no``` in my pool config file but nothing changes, same outputs – user2163438 Sep 22 '17 at 18:04
  • Get the actual path from your terminal using `echo $PATH` and then use `shell_exec("PATH= electron-pdf $inputURL $outputFile")` – Tarun Lalwani Sep 22 '17 at 18:27
  • @TarunLalwani already tried, no success... PATH is also set after modifying env vars to the correct value but it makes no difference – user2163438 Sep 22 '17 at 19:08
  • Run it like this `shell_exec("electron-pdf $inputURL $outputFile 2>&1 >/tmp/logs.txt")` and see what you get the logs – Tarun Lalwani Sep 22 '17 at 19:29

0 Answers0