bash - npm does not run when called through nginx/php-fpm exec -


i have strange issue in autodeploy script.

basically that's php script, that, when triggered through http, runs other shell script several commands npm install , npm run build. works except case when php script called http nginx/php-fpm - case npm command not run.

i created simple example repo demonstrate issue: https://github.com/kasheftin/npm-bug

we have test.php runs test.sh shell command:

<?php   exec("/home/www/tests/npm-bug/test.sh > /home/www/tests/npm-bug/test.log"); 

we have test.sh runs npm run test command:

#!/bin/bash cd /home/www/tests/npm-bug npm run test 

finally have package.json following command:

"scripts": {   "test": "echo \"hello world!\"" } 

the result of npm run test looks like:

> npm-bug@1.0.0 test /home/www/tests/npm-bug > echo "hello world!"  hello world! 

notice last row - that's result of echo command in package.json. same result appears in case of ./test.sh command. , same in test.log after running php test.php command.

but when trigger test.php http,

> npm-bug@1.0.0 test /home/www/tests/npm-bug > echo "hello world!" 

notice, last string absent, npm command did not run.

also have location rule in nginx:

location = /npm-test {   root /home/www/tests/npm-bug;   rewrite ^(.*)$ /test.php break;   include snippets/fastcgi-php.conf;   fastcgi_pass unix:/run/php/php7.0-fpm.sock; } 

this seems standart, nginx , php7.0-fpm right out of box, php config same cli , fpm. checked on 2 servers different environment.

it interesting issue solve. thing when use

  exec("/home/www/tests/npm-bug/test.sh > /home/www/tests/npm-bug/test.log"); 

it mask errors. should like

  exec("/home/www/tests/npm-bug/test.sh > /home/www/tests/npm-bug/test.log 2>&1"); 

and see big error

npm err! linux 4.4.0-66-generic npm err! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "test" npm err! node v4.2.6 npm err! npm  v3.5.2 npm err! file sh npm err! path sh npm err! code elifecycle npm err! errno enoent npm err! syscall spawn sh npm err! npm-bug@1.0.0 test: `sh -c 'echo "hello world!"'` npm err! spawn sh enoent npm err! npm err! failed @ npm-bug@1.0.0 test script 'sh -c 'echo "hello world!"''. npm err! make sure have latest version of node.js , npm installed. 

it took me sometime figure out why. added env statement shell file

user=vagrant pwd=/var/www/html/npm-bug shlvl=1 home=/home/vagrant oldpwd=/home/vagrant/nginx/html/npm-bug _=/usr/bin/env 

as can see there in no path variable defined. issue. added path variable in shell script

export path=...... 

i took path terminal showed on echo $path, , works fpm also


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -