php - Can't run node from web server -


i trying run npm php web page, never run. got exit code of 127 , no output. after doing testing narrowed down problem shebang in npm looks this:

#!/usr/bin/env node 

pretty standard, did test code:

<?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 output in browser:

string(0) "" int(127) string(6) "v8.4.0" int(0) string(28) "written jean-loup gailly." int(0) 

i enabled catch_workers_output in php-fpm config , saw in php log:

[18-aug-2017 15:15:35] warning: [pool web] child 27872 said stderr: "/usr/bin/env: " [18-aug-2017 15:15:35] warning: [pool web] child 27872 said stderr: "node" [18-aug-2017 15:15:35] warning: [pool web] child 27872 said stderr: ": no such file or directory" [18-aug-2017 15:15:35] warning: [pool web] child 27872 said stderr: "" 

i tried running exec("which node") web server , saw in php log:

[18-aug-2017 15:31:12] warning: [pool web] child 27873 said stderr: "which: no node in ((null))" 

i tried running var_dump(exec('echo $path')) , got output:

string(28) "/usr/local/bin:/bin:/usr/bin" 

this seems related how env command processes path. tried setting manually using fastcgi_param path directive in nginx.conf made no change above output.

running env alone , printing output looks this, no path entry:

array (     [0] => user=nginx     [1] => pwd=/var/www/html     [2] => shlvl=1     [3] => home=/var/cache/nginx     [4] => _=/bin/env ) 

i'm on rhel-based distro, selinux disabled, running php-fpm 5.6.31 via unix socket nginx 1.12.1. /usr/local/bin/node symbolic link /usr/local/nodejs/bin/node has 775 permissions. nginx user owns /usr/local/nodejs directory , descendants, testing purposes. suggestions?


note if run php code cli (as nginx user) works expected, related cgi/fpm environment.

$ 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 jean-loup gailly." int(0) 

you need set path environment in /etc/php5/fpm/pool.d/www.conf include /usr/local/bin/node.

in ubuntu distro commented out:

;env[path] = /usr/local/bin:/usr/bin:/bin  

so

env[path] = /usr/local/bin/node  

should job. rhel shouldn't different, if line not there, can add it.

don't forget restart php-fpm.


if nothing works, can set path explicitly when call npm:

exec('path=$path:/usr/local/bin/node npm'); 

but last resort , wouldn't recommend it.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -