You are here:Home»KB»Programming»PHP»set server environmental variables with php
Sunday, 06 May 2012 00:00

set server environmental variables with php

Written by

The following code should work on all php setups.

The following code needs to be entered on the file/thread you want the variables to be altered for. This code will on temporarily alter the enviromental variables and they will revert to what they were after the file has finished running. There is also some additional code to display the php info so you can see the variables have been altered, this section can be deleted.

<? 
$phptemp = "/var/www/vhosts/example.com/httpdocs/php.ini";
putenv("PHPRC=$phptemp");

/* the one below works */
apache_setenv("PHPRC", $phptemp);
$yo = getenv('PHPRC');
echo $yo;
phpinfo();
?>
Read 1947 times Last modified on Sunday, 03 November 2024 09:44