简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM