I'm using Nginx 1.2.4 in combination with PHP-FPM 5.4.8 with a fastcgi pass and trying to pass custom parameters to PHP. Here are the options I have found so far:
using the
envdirective to set an environment variable innginxand fetch it withgetenv()or$_ENVfromPHP. The problem is thatenvonly operates inmaincontext whereas I need to set the parameter inservercontext.using the
fastcgi_paramdirective as it's designed for that.
I have tried changing the values of some parameters using fastcgi_param but was unsuccessful:
nginx:
fastcgi_param PATH_INFO "/var/tmp";
PHP:
I checked all the predefined arrays I could find:
echo '<pre>';
echo "\n".'$GLOBALS'."\n"; var_dump($GLOBALS);
echo "\n".'$_SERVER'."\n"; var_dump($_SERVER);
echo "\n".'$_GET'."\n"; var_dump($_GET);
echo "\n".'$_POST'."\n"; var_dump($_POST);
echo "\n".'$_FILES'."\n"; var_dump($_FILES);
echo "\n".'$_REQUEST'."\n"; var_dump($_REQUEST);
echo "\n".'$_SESSION'."\n"; var_dump($_SESSION);
echo "\n".'$_ENV'."\n"; var_dump($_ENV);
echo "\n".'$_COOKIE'."\n"; var_dump($_COOKIE);
echo "\n".'$php_errormsg'."\n"; var_dump($php_errormsg);
echo "\n".'$HTTP_RAW_POST_DATA'."\n"; var_dump($HTTP_RAW_POST_DATA);
echo "\n".'$http_response_header'."\n"; var_dump($http_response_header);
echo "\n".'$argc'."\n"; var_dump($argc);
echo "\n".'$argv'."\n"; var_dump($argv);
echo '</pre>';
The only one to show PATH_INFO was $_SERVER:
var_dump($_SERVER); // ["PATH_INFO"]=> string(0) ""
But the value I set in nginx isn't taken into account.
Q1: Do I need to configure anything at nginx/php level for the fastcgi_param directive to take effect?
Q2: Is the fastcgi_param directive limited to a predefined list of parameters (e.g. I can set PATH_INFO but not custom variables of my own such as FOO)?
Q3: If yes to Q2: is there a way to pass custom parameters to PHP from Nginx?