Custom Environment Variables¶
At times, applications may require the creation of an internal server environment variable, such as you might set up with the SetEnv directive in Apache. You can set up server environment variables in OpenLiteSpeed, too.
Server Side Setup¶
Log in to the WebAdmin Console, navigate to Virtual Host > External App. For this example, let's use PHP.
In the Environment field, add the variables TEST_VALUE
and TEST_VALUE2
, like so:
TEST_VALUE=Hello
TEST_VALUE2=World
Save and restart OpenLiteSpeed.
Tip
If you are using PHP detached mode, you must first kill the lsphp
process so it may be restarted. Otherwise the new variables won't be loaded.
Application Usage¶
You can access the new variables in PHP code such as the following test.php
:
<?php
$test1 = $_SERVER['TEST_VALUE'];
$test2 = getenv('TEST_VALUE2');
echo $test1.' '.$test2;
Access test.php
from the browser, and you should see the values that were set at the server level, as in the above screenshot.