Apache Custom Environment Variables in PHP

Apache Custom Environment Variables in PHP

If you ever wanted to create a new Environment Variable, you can do so by setting them in the VirtualHost section.
For example,

<VirtualHost *:80>
     DocumentRoot      /www/htdocs
     ServerName        www.my-dom.com
     SetEnv VARNAME    varValue
</VirtualHost>

And to use it in PHP simply use $_SERVER[‘VARNAME’] or getenv(‘VARNAME’);
If you were to check the output of phpinfo(), you can actually see the Environment Variable as the image illustrates below.

Apache Environment

One thought on “Apache Custom Environment Variables in PHP

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: