0

I have written the following code: test.php

 $java_path=getenv("JAVA_HOME");
 echo 'Java Path : '.$java_path ."<br>";

when I run through command prompt (Ubuntu terminal) like:

>php test.php

Output: 
Java Path : /opt/jdk1.8.0_161

I get the expected output, but when I run it through browser (Firefox),

http://localhost/test.php

I get empty value for Java Path. Output: Java Path :

Avinash Kadam
  • 93
  • 1
  • 4
  • 2
    What do you mean by `I run through browser(Firefox), I get empty value for Java Path.`? As in you were hopeful that a PHP function would return what the java home path is on a browser? – hppycoder Apr 05 '21 at 15:01
  • 1
    What do you want to achieve? Is that path also set on the server you are running? – Nico Haase Apr 05 '21 at 15:01
  • 2
    its maybe because `JAVA_HOME` is being set for your user not for `www-data` that your webserver does its query with, – Bijay Regmi Apr 05 '21 at 15:31
  • 1
    This is because CLI is running as your user with _you_ env variables; the "browser" is using a server (apache, fastcgi, etc). This question here might help: https://stackoverflow.com/questions/13568191/how-to-get-system-environment-variables-into-php-while-running-cli-apache2hand – newfurniturey Apr 05 '21 at 15:33
  • hppycoder on command prompt (terminal) file get executed and I get output. But when I run through browser like localhost/test.php. I get nothing output. – Avinash Kadam Apr 05 '21 at 15:38
  • Please add all clarification to your question by editing it – Nico Haase Apr 05 '21 at 15:39

0 Answers0