nginx - npm install not working via php system() (exec / shell_exec) -


i installing gulp-sass among other packages using npm install. works fine using cli (with sudo su forge):

cd /path/to/package.json/ npm install 

the package.json like:

{   "name": "skeleton",   "version": "1.0.0",   "authors": [     "me <me@mycompany.co.uk>"   ],   "private": true,   "devdependencies": {     "gulp": "^3.8.11",     "gulp-autoprefixer": "^2.1.0",     "gulp-concat": "^2.5.2",     "gulp-minify-css": "^1.0.0",     "gulp-notify": "^2.2.0",     "gulp-sass": "^1.3.3",     "gulp-sourcemaps": "^1.5.2",     "gulp-uglify": "^1.2.0"   },   "dependencies": {     "node-notifier": "^4.2.1",     "streamqueue": "^0.1.3"   } } 

it works fine using php @ command line:

php -r "system('npm install');" 

but running following php via nginx/php-fpm:

<?php  set_time_limit(0); chdir('/path/to/package.json/'); echo "<pre>"; echo shell_exec('npm install 2>&1');  die(); 

outputs debug file containing following lines:

81427 error linux 4.5.5-x86_64-linode69 81428 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" 81429 error node v0.12.7 81430 error npm  v2.11.3 81431 error file sh 81432 error path sh 81433 error code elifecycle 81434 error errno enoent 81435 error syscall spawn sh 81436 error node-sass@2.1.1 install: `node scripts/install.js` 81436 error spawn sh enoent 81437 error failed @ node-sass@2.1.1 install script 'node scripts/install.js'. 81437 error problem node-sass package, 81437 error not npm itself. 81437 error tell author fails on system: 81437 error     node scripts/install.js 81437 error can info via: 81437 error     npm owner ls node-sass 81437 error there additional logging output above. 

i have tried comparing 2 scenarios following:

which npm 

both return '/usr/local/bin/npm'

--

echo $user 

both return 'forge'

--

echo $group 

both return '' (empty)

--

echo $path 

cli returns:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games 

php returns:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 

--

which sh 

both return '/bin/sh'

--

ps $$ 

cli returns:

    pid tty      stat   time command   13111 pts/2    s      0:00 bash 

php returns:

    pid tty      stat   time command   25759 ?        s      0:00 sh -c ps $$ 

--

npm -v 

both return '2.11.3'

--

npm version 

cli returns:

{ skeleton: '1.0.0',   npm: '2.11.3',   http_parser: '2.3',   modules: '14',   node: '0.12.7',   openssl: '1.0.1p',   uv: '1.6.1',   v8: '3.28.71.19',   zlib: '1.2.8' } 

php returns without skeleton 1.0.0:

{ npm: '2.11.3',   http_parser: '2.3',   modules: '14',   node: '0.12.7',   openssl: '1.0.1p',   uv: '1.6.1',   v8: '3.28.71.19',   zlib: '1.2.8' } 

--

npm config ls -l

cli returns:

; cli configs long = true user-agent = "npm/2.11.3 node/v0.12.7 linux x64"  ; userconfig /home/forge/.npmrc ignore-scripts = false loglevel = "info" prefix = "/home/forge/npm" progress = false  ; default values access = null always-auth = false bin-links = true browser = null ca = null cache = "/home/forge/.npm" cache-lock-retries = 10 cache-lock-stale = 60000 cache-lock-wait = 10000 cache-max = null cache-min = 10 cafile = undefined cert = null color = true depth = null description = true dev = false editor = "vi" engine-strict = false fetch-retries = 2 fetch-retry-factor = 10 fetch-retry-maxtimeout = 60000 fetch-retry-mintimeout = 10000 force = false git = "git" git-tag-version = true global = false globalconfig = "/home/forge/npm/etc/npmrc" globalignorefile = "/home/forge/npm/etc/npmignore" group = 1013 heading = "npm" https-proxy = null if-present = false ignore-scripts = false init-author-email = "" init-author-name = "" init-author-url = "" init-license = "isc" init-module = "/home/forge/.npm-init.js" init-version = "1.0.0" json = false key = null link = false local-address = undefined ; loglevel = "warn" (overridden) ; long = false (overridden) message = "%s" node-version = "0.12.7" npat = false onload-script = null optional = true parseable = false ; prefix = "/usr/local" (overridden) production = false proprietary-attribs = true proxy = null rebuild-bundle = true registry = "https://registry.npmjs.org/" rollback = true save = false save-bundle = false save-dev = false save-exact = false save-optional = false save-prefix = "^" scope = "" searchexclude = null searchopts = "" searchsort = "name" shell = "/bin/bash" shrinkwrap = true sign-git-tag = false spin = true strict-ssl = true tag = "latest" tag-version-prefix = "v" tmp = "/tmp" umask = 2 unicode = true unsafe-perm = true usage = false user = 1013 ; user-agent = "npm/{npm-version} node/{node-version} {platform} {arch}" (overridden) userconfig = "/home/forge/.npmrc" version = false versions = false viewer = "man" 

php returns:

; cli configs long = true user-agent = "npm/2.11.3 node/v0.12.7 linux x64"  ; userconfig /home/forge/.npmrc ignore-scripts = false loglevel = "warn" prefix = "/home/forge/npm" progress = false  ; default values access = null always-auth = false bin-links = true browser = null ca = null cache = "/home/forge/.npm" cache-lock-retries = 10 cache-lock-stale = 60000 cache-lock-wait = 10000 cache-max = null cache-min = 10 cafile = undefined cert = null color = true depth = null description = true dev = false editor = "vi" engine-strict = false fetch-retries = 2 fetch-retry-factor = 10 fetch-retry-maxtimeout = 60000 fetch-retry-mintimeout = 10000 force = false git = "git" git-tag-version = true global = false globalconfig = "/home/forge/npm/etc/npmrc" globalignorefile = "/home/forge/npm/etc/npmignore" group = 1000 heading = "npm" https-proxy = null if-present = false ignore-scripts = false init-author-email = "" init-author-name = "" init-author-url = "" init-license = "isc" init-module = "/home/forge/.npm-init.js" init-version = "1.0.0" json = false key = null link = false local-address = undefined loglevel = "warn" ; long = false (overridden) message = "%s" node-version = "0.12.7" npat = false onload-script = null optional = true parseable = false ; prefix = "/usr/local" (overridden) production = false proprietary-attribs = true proxy = null rebuild-bundle = true registry = "https://registry.npmjs.org/" rollback = true save = false save-bundle = false save-dev = false save-exact = false save-optional = false save-prefix = "^" scope = "" searchexclude = null searchopts = "" searchsort = "name" shell = "bash" shrinkwrap = true sign-git-tag = false spin = true strict-ssl = true tag = "latest" tag-version-prefix = "v" tmp = "/tmp" umask = 18 unicode = true unsafe-perm = true usage = false user = 1000 ; user-agent = "npm/{npm-version} node/{node-version} {platform} {arch}" (overridden) userconfig = "/home/forge/.npmrc" version = false versions = false viewer = "man" 

--

potentially relevant config differences reported are:

- group (1013 / 1000) - shell (/bin/bash / bash) - i've tried using /bin/bash -c "npm install" seems make no difference. - umask (2 / 18) - user (1013 / 1000) (user 1000 "forge", user 1013 myself) 

i'm out of ideas. if have idea why introduction of nginx/php-fpm causes issue, input appreciated.

many thanks.


Comments