PHP exec Java cmd失败,权限被拒绝

我目前正在编写一些需要调用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

enter image description here


解决方法:

我有一个类似的问题.我在RedHat 7(安装在Amazon EC2上)上复制了它.
只有当selinux切换到许可模式时 – 问题才得以解决.

> Sudo或以root用户身份登录
>检查状态:$sestatus或$getenforce.
>要关闭它:

>临时:$setenforce 0.
>永久:编辑/ etc / selinux / config文件

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

更多信息here.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...