I tried to start npmfrom a PHP web page, but it will never start. I always got exit code 127 and did not output. After some testing, I narrowed the problem down to shebang in npm, which looks like this:
Pretty standard, but I did some test codes:
<?php
$result = exec("/usr/bin/env node --version", $output, $exit);
var_dump($result);
var_dump($exit);
$result = exec("node --version", $output, $exit);
var_dump($result);
var_dump($exit);
$result = exec("/usr/bin/env gzip --version", $output, $exit);
var_dump($result);
var_dump($exit);
And got this output in my browser:
string(0) ""
int(127)
string(6) "v8.4.0"
int(0)
string(28) "Written by Jean-loup Gailly."
int(0)
I included catch_workers_outputPHP-FPM in the configuration and saw this in the PHP log:
[18-Aug-2017 15:15:35] WARNING: [pool web] child 27872 said into stderr: "/usr/bin/env: "
[18-Aug-2017 15:15:35] WARNING: [pool web] child 27872 said into stderr: "node"
[18-Aug-2017 15:15:35] WARNING: [pool web] child 27872 said into stderr: ": No such file or directory"
[18-Aug-2017 15:15:35] WARNING: [pool web] child 27872 said into stderr: ""
I also tried starting exec("which node")from a web server and saw this in the PHP log:
[18-Aug-2017 15:31:12] WARNING: [pool web] child 27873 said into stderr: "which: no node in ((null))"
I tried to run var_dump(exec('echo $PATH'))and got this output:
string(28) "/usr/local/bin:/bin:/usr/bin"
This is similar to how the team envprocesses the path. I tried to install it manually using the directive fastcgi_param PATHin nginx.conf, but it did not change the above output.
env : PATH:
Array
(
[0] => USER=nginx
[1] => PWD=/var/www/html
[2] => SHLVL=1
[3] => HOME=/var/cache/nginx
[4] => _=/bin/env
)
RHEL SELinux, PHP-FPM 5.6.31 UNIX Nginx 1.12.1. /usr/local/bin/node /usr/local/nodejs/bin/node, 775 . nginx /usr/local/nodejs . ?
, PHP- CLI ( nginx), , , CGI/FPM.
$ su -s "/bin/sh" -c "/var/www/html/test.php" nginx
string(6) "v8.4.0"
int(0)
string(6) "v8.4.0"
int(0)
string(28) "Written by Jean-loup Gailly."
int(0)