Access Environment Variables

I am trying to store sensitive information in environment variables that I pass into CS-Cart. But the ways I have tried so far have not worked.



In the terminal I am setting the env variable by using export


export FOO=bar



But this is not available in config.local.php through any of the following methods:



echo getenv("FOO");
echo $_SYSTEM["FOO"];
echo $_ENV["FOO"];




Any help would be appreciated.

I would guess that PHP has some security features built in where it only recognizes environment variables that are configured in php.ini.



Why aren't you just POSTing the data to the cart and letting an addon controller handle the posting?

I am trying not to store my database password in config.local.php for security reasons …



I figured out a solution. I wrote a ruby script to replace the values in the config.local.php file with the defined environment variables.


```php

#!/usr/bin/env ruby



file_names = ['path/to/config.local.php']



config_values = [

'CS_CART_DB_HOST',

'CS_CART_DB_NAME',

'CS_CART_DB_USER',

'CS_CART_DB_PASSWORD',

'CS_CART_HTTP_HOST',

'CS_CART_HTTP_PATH',

'CS_CART_HTTPS_HOST',

'CS_CART_HTTPS_PATH',

'CS_CART_CUSTOMER_INDEX',

'CS_CART_ADMIN_INDEX'

]



file_names.each do |file_name|

text = File.read(file_name)

config_values.each do |config_value|

search_regexp = /%#{Regexp.quote(config_value)}%/

next if ENV[config_value].nil?

p ENV[config_value]

text = text.gsub(search_regexp, ENV[config_value])

end


To write changes to the file, use:

File.open(file_name, “w”) {|file| file.puts text }

end

```