本文介绍了PHP exec Java cmd失败,权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在编写一些需要调用jar的PHP脚本。我编写了一个测试脚本来测试Java -version cmd。
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);
页面返回如下:
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是正常的。
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?
更新:这是hs_error.log
Update: Here is the hs_error.log
推荐答案
我有类似的问题。我在RedHat 7上复制了它(安装在Amazon EC2上)。
只有当selinux切换到许可模式时 - 问题才得以解决。
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.
- Sudo或以
root登录
- 检查状态:
$ sestatus
或$ getenforce
。 - 要关闭它:
- 临时:
$ setenforce 0
。 - 永久:编辑
/ etc / selinux / config
文件
- 临时:
- Sudo or login as
root
- To check the status:
$ sestatus
or$ getenforce
. - To turn it off:
- temporary:
$ setenforce 0
. - permanently: edit
/etc/selinux/config
file
- temporary:
经过深入研究后,看起来最好启用apache来使用内存并没有关闭模式:
setsebool -P httpd_execmem 1
更多info 。
这篇关于PHP exec Java cmd失败,权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!