Setting $_ENV (fka $HTTP_ENV_VARS) with nginx/php-fpm

后端 未结 2 1424
无人及你
无人及你 2021-02-08 19:08

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 n

2条回答
  •  失恋的感觉
    2021-02-08 19:23

    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;
    }
    

提交回复
热议问题