0

I'm trying to query environment variables that i have set my .bashrc file (i'm running Ubuntu 14.04) in a PHP scripts that run's under Apache server.

When i query the getenv('MY_VAR_NAME') or $_ENV['MY_VAR_NAME'] while accessing the page, it seems that those variables are missing..

My guess is: when the script is been executed the user is www-data, so 'MY_VAR_NAME' is not accessible.

Is there any procedures / best practices to this kind of problems ?

Thanks

Ofer Velich
  • 307
  • 1
  • 2
  • 6

1 Answers1

0

Without going into why you need to access a specific variable, you can set them in your Apache configuration, by adding:

SetEnv VARIABLE_NAME variable_value

To your VirtualHost block or .htaccess file.

Alternatively, if you could explain what your script does and why it needs the environment variable, we could suggest a different way of doing.

Mark R.
  • 363
  • 1
  • 5
  • That's i know, i have been trying to avoid it form my own reasons, is there any way to do it aside of that ? and is that unsafe to expose the user ubuntu env variable to www-data ? – Ofer Velich Feb 18 '15 at 15:02
  • Again, it depends on your application's needs. I don't see an inherent risk in passing specific variables to Apache. – Mark R. Feb 18 '15 at 15:11
  • Great thanks, seems like adding the environment variables to the "/etc/apache2/envvars" did the trick – Ofer Velich Feb 18 '15 at 15:43