Write down your apache environment variables and read them into PHP script
I have an index.php file running some script executing mysql queries. For the obvious security reason I would like to remove the mysql credentials (host, password, user, database) from this script and replace them with some apache environment variables.
I tried to create variables like this in / etc / apache 2 / envvars using the following line of code: export MYSQL_USER='my_user'
and then I intend to return it using the getEnv php function like this: getenv('MYSQL_USER')
but that returns nothing.
Any idea? Thank!
source to share
In a virtual host for Apache you can use
SetEnv VARIABLE_NAME value
and get the value of that variable from your PHP code using
$variable = getenv('VARIABLE_NAME');
You can read more about SetEnv here http://httpd.apache.org/docs/2.2/mod/mod_env.html#setenv
source to share