dongzanghui4624 2019-07-28 13:47
浏览 304

使用php exec函数执行node命令时出错

I'm trying to execute a nodejs file from php on a Centos server. When the command is executed from the terminal it works fine (also after switching to apache user with the following command su -s /bin/bash apache), but when the code is executed while browsing the file it throws the following exception:

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

  • I have changed also to absolute path, but no luck.
  • Gave 777 permission to index.js file.
  • Testet from terminal and works fine:

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;
    }
?>
  • 写回答

1条回答 默认 最新

  • duanmei1694 2019-08-02 14:34
    关注

    If you are using selinux, try disabling it temporary:

    setenforce 0
    

    Try to run your node.js script. If it run, you probably need to change selinux httpd settings. Do following command to list all selinux settings for httpd service:

    /usr/sbin/getsebool -a | grep httpd
    

    You will see two relevant settings httpd_ssi_exec and httpd_execmem. Set them on with:

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

    After that try to enable selinux again and run your node.js script to see if the change helped:

    setenforce 1
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab