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.


#!/usr/bin/env ruby

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

config_values = [












file_names.each do |file_name|

text =

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])


To write changes to the file, use:, “w”) {|file| file.puts text }