【问题标题】:PHP exec Java cmd failed with permission deniedPHP exec Java cmd因权限被拒绝而失败
【发布时间】:2016-09-02 06:01:53
【问题描述】:

我目前正在编写一些需要调用 jar 的 PHP 脚本。我写了一个测试脚本来测试 Java -version cmd。

echo exec('whoami');
echo '<hr/>';

exec('java -version', $out);
var_dump($out);

页面返回如下:

apache
array(6) { [0]=> string(134) "OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00007ff705000000, 2555904, 1) failed; error='Permission denied' (errno=13)" [1]=> string(1) "#" [2]=> string(76) "# There is insufficient memory for the Java Runtime Environment to continue." [3]=> string(100) "# Native memory allocation (malloc) failed to allocate 2555904 bytes for committing reserved memory." [4]=> string(57) "# An error report file with more information is saved as:" [5]=> string(29) "# /tmp/jvm-26720/hs_error.log" }

我在控制台测试了cmd,正常。

[root@localhost ~]# java -version
java version "1.7.0_45"
OpenJDK Runtime Environment (rhel-2.4.3.3.el6-x86_64 u45-b15)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)

有没有人可以帮我解决这个问题?

更新:这是 hs_error.log

【问题讨论】:

  • 在控制台中尝试执行:sudo --user=apache java -version 以确保您没有以某种方式为一般的 apache 用户设置某种内存限制。
  • 另外,/tmp/jvm-26720/hs_error.log 有什么?
  • @Mike 我已经用 error.log 更新了这个问题。更重要的是,我无法在控制台上执行“sudo --user=apache java -version”成功。
  • 执行时会发生什么?你也遇到同样的错误吗?
  • @Mike 我在控制台执行了 cmd java -version 成功。

标签: java php memory exec permission-denied


【解决方案1】:

我遇到了类似的问题。我在 RedHat 7 上复制了它(安装在 Amazon EC2 上)。
仅当 selinux 切换到许可模式时 - 问题已修复。

  1. Sudo 或以root 登录
  2. 检查状态:$ sestatus$ getenforce
  3. 要关闭它:
    • 临时:$ setenforce 0
    • 永久:编辑/etc/selinux/config文件

经过深入研究,看来最好开启“apache使用内存”而不是关闭模式:
setsebool -P httpd_execmem 1

更多信息here

【讨论】:

    猜你喜欢
    • 2015-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-01
    • 2022-01-22
    相关资源
    最近更新 更多