PHP exec Java cmd failed with permission denied

五迷三道 提交于 2019-12-18 07:14:20

问题


I am currently writing some PHP scripts that need to invoke jar. I wrote a test script to test Java -version cmd.

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

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

The page return as below:

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" }

I have test the cmd in the console and it is normal.

[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)

Is there anyone who can help me with this?

Update: Here is the hs_error.log


回答1:


I had a similar issue. I duplicated it on the RedHat 7 (installed on the Amazon EC2).
Only when selinux was switched to the permissive mode - the issue was fixed.

  1. Sudo or login as root
  2. To check the status: $ sestatus or $ getenforce.
  3. To turn it off:
    • temporary: $ setenforce 0.
    • permanently: edit /etc/selinux/config file

After deeper research, it looks that it is better to enable "apache to use the memory" and not turn off the mode:
setsebool -P httpd_execmem 1

More info here.



来源:https://stackoverflow.com/questions/39285304/php-exec-java-cmd-failed-with-permission-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!