简体   繁体   中英

Set environmental variables for the command line AND webserver (PHP)

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM