Issue
When trying to run signal-cli via Symfony it errors:
JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation.
Output of echo $JAVA_HOME
in the working directory:
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-0.fc31.x86_64/jre
Output of java -version
in the working directory:
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-bit Server VM (build 25.252-b09, mixed mode)
I'm trying to figure out how to resolve the error. Here is my code:
public function list()
{
$list = new Process(['.././signal-cli-0.6.8/bin/signal-cli']);
$list->run();
if (!$list->isSuccessful()) {
throw new ProcessFailedException($list);
}
echo $list->getOutput();
}
}
Solution
From docs (emphasis mine):
In addition to the env vars passed explicitly, processes inherit all the env vars defined in your system. You can prevent this by setting to false the env vars you want to remove [...]
source: https://symfony.com/doc/current/components/process.html#setting-environment-variables-for-processes
I believe that means that your user's/shell's env vars don't matter in that moment and you might have to set those explicitly:
$process = new Process(['...'], null, ['ENV_VAR_NAME' => 'value']);
anyhow, you could write a small script that just writes the result of env
/printenv
into a file for further inspection. There's most likely a big difference, due to your shell running lots of additional scripts that impact environment that are not forwarded nor run for your process.
So you might have to explicitly pass JAVA_HOME to the process as implied above (this is a very specific home path, ):
$process = new Process(['...'], null, [
'JAVA_HOME' => '/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-0.fc31.x86_64/jre',
]);
Answered By - Jakumi Answer Checked By - Candace Johnson (WPSolving Volunteer)