'how to set environment variables in apache xampp ?
I would like to add some environment variables in apache xampp in windows. I already tried the following : adding this in httpd.conf
SetEnv ENVIRONMENT "setting"
or, run this script
putenv("ENVIRONMENT='setting'");
but that doesn't seem to work when I echo phpinfo(), there isn't ENVIRONMENT variable in the environment section
Solution 1:[1]
I know this is an old post and the OP already may has solved this by himself but for others:
SetEnv ENVIRONMENT setting
This would be the correct Syntax inside of the httpd.conf file. Also, this code should be put at the end of the file.
After saving httpd.conf the apache server needs to be restarted. Otherwise the environment variable will not be set in "this" apache session!
Sincerely, Kami Yang
Solution 2:[2]
No server restart required if you add your environment variables to a .htaccess file in your code directory. For example if you have a PHP app under the directory P:\xampp7.3\htdocs\MyTestApp
, add a P:\xampp7.3\htdocs\MyTestApp\env-test.php
script and copy the line of code below into it:
<?php echo getenv('APPLICATION_NAME'); // print APPLICATION_NAME environment variable ?>
Next create a P:\xampp7.3\htdocs\MyTestApp\.htaccess
file and add:
SetEnv APPLICATION_NAME "Testing my application environment variable"
When you run the env-test.php
script, it should print
Testing my application environment variable
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | w. Patrick Gale |