Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reinitialize system wide environment variable in linux

I just want my apache to register some of my predefined environment so that i can retrieve it using getenv function in php. How can i do this? I tried adding /etc/profile.d/foo.sh with export FOO=/bar/baz using root and restarted apache.

like image 878
ken Avatar asked Sep 22 '08 10:09

ken


People also ask

Are environment variables system wide?

Environment variables are variables that are available system-wide and are inherited by all spawned child processes and shells. Shell variables are variables that apply only to the current shell instance.

How do I permanently remove an environment variable in Linux?

Delete Environment Variables You need to just use the unset command with the variable name to delete it. This command will remove the variable permanently.


1 Answers

Environment variables are inherited by processes in Unix. The files in /etc/profile.d are only executed (in the current shell, not in a subshell) when you log in. Just changing the value there and then restarting a process will not update the environment.

Possible Fixes:

  • log out/log in, then start apache
  • source the file: # . /etc/profile.d/foo.sh, then restart apache
  • source the file in the apache init script

You also need to make sure that /etc/profile.d/ is sourced when Apache is started by init rather than yourself.

The best fix might also depend on the distribution you are using, because they use different schemes for configuration.

like image 196
Torsten Marek Avatar answered Sep 26 '22 04:09

Torsten Marek