gustavo martins
gustavo martins

Reputation: 83

Apache can't read my environment variables

I created an environment variable called API_KEY on my linux server, when I run the following command on php, I get false, meaning there is no variable with that name.

$api = getenv("API_KEY");

I created the variable following this steps:

created a keys.sh file in /etc/profile.d/ and saved my variable with this format API_KEY="my variable value"

When I run the "printenv" command as user-ec2 or root I can see the environment variable is there, but what it seems to be the problem is that when apache tries to access it dosen´t show up, I don´t know what to do so that the apache user can find this variable.

Upvotes: 0

Views: 1982

Answers (1)

gustavo martins
gustavo martins

Reputation: 83

I went to etc/httpd/conf, where my httpd.conf file was located and created the environment variables using:

SetEnv API_KEY API_KEY_VALEU

Now the apache user could return the environment variable when I used:

getenv('API_KEY');

Upvotes: 3

Related Questions