McKenneii
McKenneii

Reputation: 286

getenv() is working in browser but not in command line

On my server, I have an environement variable set to 'valueOfMyVariable'. My problem is that getenv() return false if I run the file in command line, but true if I run it from a browser.

<?php var_dump( getenv('myEnvVariable') ) ?>

Running this code from the command line ( php myfilename.php) will return 'false'.

Running this code from a browser returns 'valueOfMyVariable'.

I'm expecting from both call to have 'valueOfMyVariable' as a result.

Does anyone know why in the first case, I have false instead of my variable ? Does that problem comes from a configuration problem ?

If I'm not clear enough feel free to ask for precision, the problem is simple but it's hard to explain it properly as English is not my main language.

Upvotes: 1

Views: 1703

Answers (1)

Barmar
Barmar

Reputation: 781300

Sounds like you didn't export the environment variable in your terminal session.

export myEnvVariable=someValue
php myfilename.php

It's presumably working in the browser because the webserver is setting the environment variable.

Upvotes: 1

Related Questions