gradlew 通过 ssh 成功构建但在 CENTOS 7 中因 php exec ERROR "Please set the JAVA_HOME variable" 而失败

gradlew build successfully by ssh but faild by php exec ERROR "Please set the JAVA_HOME variable" in CENTOS 7

我在.bash_profile和环境文件中设置了JAVA_HOME。 当 运行 gradlew 通过 centos 中的终端构建 seccessfull 时,但是当 运行 通过 php 执行相同命令时得到 JAVA_HOME ERROR

$command = "$path/gradlew -c $path/settings.gradle assembleRelease";
exec($command, $output, $code);

错误:"Please set the JAVA_HOME variable in your environment to match the"

已通过在命令字符串

中发送 java_home 修复
$javaHome = "JAVA_HOME=/opt/jdk1.8.0_161";
$command = "$javaHome $path/gradlew -c $path/settings.gradle assembleRelease";
exec($command, $output, $code);