0

I have some environment variables as bash variable and other environment variables into a .env file.
In my php script I load env variable using this

require __DIR__.'/vendor/autoload.php';
use Dotenv\Dotenv;

$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();

but in this way I have only the .env file variables, how can I get the bash environment variables???

Vito Lipari
  • 795
  • 8
  • 35

1 Answers1

0

This should work

// Example use of getenv()
$ip = getenv('REMOTE_ADDR');

// Or simply use a Superglobal ($_SERVER or $_ENV)
$ip = $_SERVER['REMOTE_ADDR'];

from the PHP documentation, https://www.php.net/manual/en/function.getenv.php

Shaqil Ismail
  • 1,794
  • 1
  • 4
  • 5
  • `$_ENV` and `getenv ` get the same result of `$dotenv->load()` and the result is the file .env variables, `$_SERVER` get the http request variables. I need the bash environment variables ( or the Operating System environment variables ) – Vito Lipari Aug 18 '21 at 12:22
  • I think your .env file is overwriting the bash variables which are already available. Try to get a bash environment variable without loading your .env file. – Shaqil Ismail Aug 19 '21 at 17:24