使用nginx / php-fpm设置$ _ENV(fka $ HTTP_ENV_VARS) [英] Setting $_ENV (fka $HTTP_ENV_VARS) with nginx/php-fpm
问题描述
使用apache,我可以设置envSOMEENV,并通过$ _ENV ['SOMEENV']访问php,但我不知道如何使用nginx + php-fpm。 p>
我最初以为我只需要在我的php-fpm池的配置中设置ENV [SOMENEV] = test,但是var_dump($ _ ENV)仍然没有返回任何内容。 p>
任何提示?
nginx没有办法影响php的环境,因为它没有将php解释器嵌入到其进程中。它通过 fastcgi_param 指令将参数传递给php。您可以添加一个您设置其余参数的地方,并通过$ _SERVER进行访问:
location〜\.php $ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $ request_filename;
fastcgi_param SOMEENV测试;
fastcgi_pass php;
}
What is the equivalent of setenv in a apache environment? With apache I am able to for example set the env "SOMEENV" and access it in php via $_ENV['SOMEENV'] - but I have no idea how to do it with nginx+php-fpm.
I initially thought that I just have to set ENV[SOMENEV]=test in the config of my php-fpm pool, but var_dump($_ENV) still returns nothing.
Any hints?
nginx doesn't have a way of affecting php's environment, since it doesn't embed the php interpreter into its process. It passes parameters to php through fastcgi_param directives. You can just add one where you set the rest of your params and access it via $_SERVER:
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SOMEENV test;
fastcgi_pass php;
}
这篇关于使用nginx / php-fpm设置$ _ENV(fka $ HTTP_ENV_VARS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!