Thursday, 27 June 2019

Passing an environment-variable into a php commandline script

I want to set an environment-variable, then access it in PHP, but cannot find how to do so.

In the (linux) shell, I run:

$ APP_ENV="development"
$ export $APP_ENV

Then I run a simple test script testenv.php:

<?php
print $_ENV["APP_ENV"];
print getenv("APP_ENV");

From the same shell where that variable was set:

$ php testenv.php

This Prints nothing and throws a notice:

Notice: Undefined index: APP_ENV in /xxxx/envtest.php on line 2

Notice makes sense, because APP_ENV is simply not found in the environment-variables, getenv() throws no warning but simply returns nothing.

What am I missing?



from Passing an environment-variable into a php commandline script

No comments:

Post a Comment