0

I am trying to set up a permanent "environment" variable per this SO Post.

I put the variable in my .bash_profile and am able to access it from the command line using.

echo $VAR

However, this is a DSN ( DB Credentials ) needed by PHP ( same thing Heroku does ) and I need to access it using

getenv() or similar.

If I run env from the command line I do not see it listed.

It appears there are different types of environment variables and I'm using the wrong one.

How should I do this correctly?

Community
  • 1
  • 1
cade galt
  • 3,843
  • 8
  • 32
  • 48

1 Answers1

1

Your webserver does not run your shell so it doesn't the .bash_profile. There are various tricks to get environment variables into Apache but they all rely on having administration access to your webserver, and you don't get that on low-end godaddy hosting.

If you were to explain why you are trying to get environment variables into Apache, what type of hosting you have and what access you have to the server we might be able to better advise. There are modules which expose access to manipulate environment variables for Apache (mod_env for example) but these may not be available/appropriate. It's also possible to get data (and code) into PHP from a .htaccess file, but again its impossible to say whether this meets your requirements.

symcbean
  • 47,736
  • 6
  • 59
  • 94
  • For consistency and correlation. I deploy to multiple servers and this is the way I want to do it. I prefer to keep my credentials on the server in a file that is not tracked by git. Obviously I could just create a file and read from it ... but I was hoping this was a not rocket science and I could just do it the same way Heroku does. And of course I could keep it in the repo and .gitignore it but, I'm still learning git and don't trust it. – cade galt Jan 11 '16 at 21:17
  • I could put it in the .htaccess which I of course have access, but this defeats the purpose. I want it in the OS files. I just feel this is safer. – cade galt Jan 11 '16 at 21:23
  • If your objective is to keep it out of got then keep it outside the document root and outside of your project. Just use an include file. – symcbean Jan 11 '16 at 23:24
  • Well, yea but I want to do the same thing Heroku does and keep it as an environment variable, unless I don't have access to do this on a shared account. – cade galt Jan 12 '16 at 18:29