我正在尝试在 Centos 服务器上从 php 执行 nodejs 文件。当从终端执行该命令时,它工作正常(在使用以下命令 su -s/bin/bash apache 切换到 apache 用户之后),但是当在浏览文件时执行代码时,它会引发以下异常:
["","","#","# Fatal error in , line 0","# Check failed: SetPermissions(protect_start, protect_size, PageAllocator::kReadExecute).","#","#","# ","#FailureMessage 对象:0x7fffd9b37760"]
php -r 'echo exec("/usr/bin/node/var/www/html/index.js/var/www/html/source_files/2>&1");'
<?php
try {
exec("/usr/bin/node /var/www/html/index.js /var/www/html/source_files/ 2>&1", $out, $err);
if ($err == 0) {
return 1;
} else {
return 0;
}
} catch (Exception $e) {
error_log($e);
return 0;
}
?>
最佳答案
如果您使用的是 selinux,请尝试暂时禁用它:
setenforce 0
尝试运行你的 node.js 脚本。如果它运行,您可能需要 更改 selinux httpd 设置 .执行以下命令列出 httpd 服务的所有 selinux 设置:
/usr/sbin/getsebool -a | grep httpd
你会看到两个相关的设置
httpd_ssi_exec
和 httpd_execmem
.设置它们:
setsebool -P httpd_ssi_exec=1
setsebool -P httpd_execmem=1
之后尝试再次启用 selinux 并运行 node.js 脚本以查看更改是否有帮助:
setenforce 1
关于php - 使用 php exec 函数执行 Node 命令时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57241521/