最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

基于npm的命令无法通过php shell

运维笔记admin21浏览0评论

基于npm的命令无法通过php shell

基于npm的命令无法通过php shell

我有一个测试脚本来尝试调试一些我通过PHP的shell_exec()函数使用npm / gulp的问题;

<?php $command_feedback = []; $command_feedback[] = shell_exec('pwd'); $command_feedback[] = shell_exec('npm'); $command_feedback[] = shell_exec('npm install'); $command_feedback[] = shell_exec('gulp build'); error_log(print_r([$command_feedback], true));

这将立即输出

[0] => Array ( [0] => /var/www/local.domain/public [1] => [2] => [3] => )

这正在虚拟机上运行

    Centos 6.10
  • PHP 7.3.10
  • npm 6.9
  • 节点10.16.3
  • 如果我以apache用户身份在CLI中登录,请cd到此目录并运行npm installgulp build,这些命令就可以正常工作。

但是如果我自己输入npmnode,我似乎确实会遇到一些权限错误;

bash-4.1$ npm Error: EACCES: permission denied, scandir '/root' (node:2816) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'loaded' of undefined at exit (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:98:27) at errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:216:3) at /usr/local/lib/node_modules/npm/bin/npm-cli.js:77:20 at cb (/usr/local/lib/node_modules/npm/lib/npm.js:225:22) at /usr/local/lib/node_modules/npm/lib/npm.js:263:24 at /usr/local/lib/node_modules/npm/lib/config/core.js:83:7 at Array.forEach (<anonymous>) at /usr/local/lib/node_modules/npm/lib/config/core.js:82:13 at f (/usr/local/lib/node_modules/npm/node_modules/once/once.js:25:25) at /usr/local/lib/node_modules/npm/lib/config/core.js:112:20 (node:2816) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:2816) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. TypeError: Cannot read property 'loaded' of undefined at process.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:40:18) at process.emit (events.js:198:13) /usr/local/lib/node_modules/npm/lib/utils/error-handler.js:98 var doExit = npm.config.loaded ? npm.config.get('_exit') : true ^ TypeError: Cannot read property 'loaded' of undefined at exit (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:98:27) at process.errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:216:3) at process.emit (events.js:198:13) at process._fatalException (internal/bootstrap/node.js:496:27)

我刚刚完全卸载并重新安装了node / npm来尝试对其进行调试,但似乎没有什么区别。 node / npm以root用户身份安装。

过去大约一周前就可以使用,并且在运行上述相同版本的同事的计算机上,它在所有情况下都可以使用,因此我不确定这是怎么回事。权限听起来像是问题,但是我不确定为什么以apache用户身份登录而不是在shell_exec()

下使用命令

我有一个测试脚本来尝试调试一些我通过PHP的shell_exec()函数使用npm / gulp的问题;

回答如下:尝试
发布评论

评论列表(0)

  1. 暂无评论