Unable to exec("java -version") in php osx -


php in osx yosomite unable execute following code successfully.

<?php            exec("java -version 2>&1", $output, $returnvalue);         print_r($returnvalue);         print_r($output); ?> 

the output is

1array ( [0] => no java runtime present, requesting install. [1] => 2015-07-16 21:25:05.588 java[1434:49304] jlrequestruntimeinstall: error calling: cfmessageportcreateremote ) 

i can run command line. tried changing apache user didn't help.

in php, don't have access normal search paths executables such java; why can run in terminal not in php code. safety feature not import search paths in shell $path variable server-side languages such php.

although could export path variable exec subshell, shouldn't. full path java executable preferred. remember environment variables available php (such path) user under php runs -- restricted user security reasons.

if you're interested in going environment variable approach, i'd recommend restricted environment. depending upon particular setup, following question on (for apache / php) may give starting point: https://stackoverflow.com/questions/13568191/how-to-get-system-environment-variables-into-php-while-running-cli-apache2hand


Comments