Reputation: 24315
I am using PHP and NGINX and Mac/linux. I'd like to set environmental variables such that they are accessible from scripts run from the command line or via the webserver.
Setting $_SERVER
fastcgi params in my nginx configuration doesn't work because then they aren't available in cron jobs that run via the command line.
For security reasons, setting the variables in the web app itself is not a good idea so I don't want to do that either.
What's the right way to do this?
Upvotes: 0
Views: 1054
Reputation: 78984
One way is to set auto_append_file
in php.ini
to a PHP file that has setenv()
lines. Then use getenv()
. I'm not sure if OSX has seperate php.ini
files for web and cli.
Just reread and saw you state Mac/Linux. For Linux you can set these variables in /etc/profile
or files in /etc/profile.d
. A quick search shows /etc/launchd.conf
for OSX. Not sure of the scope of these files but may be worth a try.
Upvotes: 1