Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

define variable in linux that can be access in php [closed]

I add a variable in whole linux varibale in /etc/profile

export MYNAME="My Value"

how can i access this value in php source code during run via apache web server? in $_SERVER this value doesn't exist.

just this keys appear on $_ENV:

_ENV["APACHE_RUN_DIR"]  /var/run/apache2
_ENV["APACHE_PID_FILE"] /var/run/apache2.pid
_ENV["PATH"]            /usr/local/bin:/usr/bin:/bin
_ENV["APACHE_LOCK_DIR"] /var/lock/apache2
_ENV["LANG"]            C
_ENV["APACHE_RUN_USER"] www-data
_ENV["APACHE_RUN_GROUP"]    www-data
_ENV["APACHE_LOG_DIR"]  /var/log/apache2
_ENV["PWD"]                 /
like image 554
sweb Avatar asked Nov 03 '12 13:11

sweb


2 Answers

Assuming the variables are exported under the correct user, $_ENV should contain them.

See: http://se.php.net/manual/en/reserved.variables.environment.php

like image 183
Jani Hartikainen Avatar answered Sep 25 '22 15:09

Jani Hartikainen


Trying to set an environment variable for a daemon process is trickier than it sounds. Only interactive login bash shells source /etc/profile, which probably doesn't match the criteria of your web server process. See this page for more information.

However, you can set environment variables in Apache and PHP.

In Apache configuration file:

SetEnv ENV_VAR var_value

Restart, the server. Then you should be able to fetch this variable using $_ENV in PHP.

like image 21
Geoff Montee Avatar answered Sep 22 '22 15:09

Geoff Montee