centos 使用php exec函数执行节点命令时出错

iugsix8n  于 6个月前  发布在  PHP
关注(0)|答案(1)|浏览(98)

我尝试在Centos服务器上从php执行一个nodejs文件。当命令从终端执行时,它工作正常(在使用以下命令su -s /bin/bash apache切换到apache用户后也是如此),但是当代码在浏览文件时执行时,它抛出以下异常:

[",","#","# Fatal error in,line 0”,"# Check failed:SetPoint(protect_start,protect_size,PageAllocator::kReadExecute).","#FailureMessage Object:0x7fffd9b37760”]

  • 我也改了绝对的道路,但没有运气。
  • 已授予777访问index.js文件的权限。
  • 从终端测试,工作正常:
  • 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;
    }
?>

字符串

hsgswve4

hsgswve41#

如果你使用的是selinux,试着暂时禁用它:

setenforce 0

字符串
尝试运行你的node.js脚本。如果它运行,你可能需要更改selinux httpd设置。执行以下命令列出httpd服务的所有selinux设置:

/usr/sbin/getsebool -a | grep httpd


您将看到两个相关设置httpd_ssi_exechttpd_execmem。使用以下命令将其设置为:

setsebool -P httpd_ssi_exec=1
setsebool -P httpd_execmem=1


之后,尝试再次启用selinux并运行node.js脚本,看看更改是否有帮助:

setenforce 1

相关问题