Thursday, January 20, 2011

executing java from php in rhel/centos - not enough space for code cache

The apache user could run java programs just fine from the command line, but even the simplest java command in php would fail:
<?php
system('java -version');
?>

with the error 
Error occurred during initialization of VM
Could not reserve enough space for code cache

We already had the setsebool -P httpd_ssi_exec=1 option on, so that Apache had permission to execute whatever. Strangely, however, this "memory" issue is also due, somehow to selinux. Disabling selinux temporarily (e.g. with echo 0 >/selinux/enforce) or setting setsebool -P httpd_disable_trans=1 fixes the problem. I'd like less of a sledgehammer solution, but messing with other selinux settings does not seem to have any effect.


Edit: As a commenter below just indicated, you can use setsebool -P httpd_execmem=1 to disable this setting. If that doesn't work, well, back to the sledgehammer.

6 comments:

  1. Ah, eureka indeed! That was it for us, too!

    ReplyDelete
  2. For those searching in the future, I solved this issue on CentOS 6.2 by issuing the command:

    setsebool httpd_execmem=1

    ReplyDelete
    Replies
    1. Ah, yes, thanks for the setsebool command (as I re-encounter this issue on a second machine)! This allows me to keep SELimux active, instead of just nuking the whole thing. And I see from the man page that the -P option makes the setting persist across reboots, which was my next concern. And now we can run the Java authentication module to log into our new wiki!

      Delete
  3. paxctl -c -m /usr/bin/keytool
    paxctl -c -m /usr/bin/java

    did the trick for me

    ReplyDelete

Note: Only a member of this blog may post a comment.