How to get PHP to be able to read system environment variables(如何让 PHP 能够读取系统环境变量)
问题描述
我在 Centos 上使用 PHP 作为 PHP-FPM.我正在尝试遵循将设置存储在环境变量中的 http://12factor.net/ 准则.
I am using PHP as PHP-FPM on Centos. I am trying to follow the http://12factor.net/ guidelines of having the settings be stored in environment variables.
我在/etc/profile.d 中创建了一个文件,用于设置我想要的环境变量,并且当通过 Bash 在 CLI 中进行测试(即运行 bash 脚本)时会出现环境变量:
I have created a file in /etc/profile.d that sets the environment variables I want, and the environment variables appear when tested in the CLI via Bash i.e. running the bash script:
echo $SOME_SERVER_SETTING
显示正确的输出.
我已将 clear_env 设置为 false 并将 variables_order 设置为 EGPCS,但是,我设置的变量也未显示在 PHP 中 getenv('SOME_SERVER_SETTING')或做 var_dump($_ENV)
I have set the clear_env setting to false and variables_order to EGPCS, however, the variable I have set does not show up in PHP either getenv('SOME_SERVER_SETTING') or doing var_dump($_ENV)
需要设置哪些其他设置以允许 PHP-FPM 接收所有服务器环境变量,尤其是通过 Centos 上/etc/profiles.d 中的 shell 脚本设置的那些?
What other setting needs to be set to allow PHP-FPM to receive all of the server environment variables, and in particular those set through a shell script in /etc/profiles.d on Centos?
推荐答案
安全原因:-)
参见 /etc/php5/fpm/pool.d/www.conf(debian 位置,在 CentO 上可能不同)
See /etc/php5/fpm/pool.d/www.conf (debian location, may be different on CentOs)
; Clear environment in FPM workers
; Prevents arbitrary environment variables from reaching FPM worker processes
; by clearing the environment in workers before env vars specified in this
; pool configuration are added.
; Setting to "no" will make all environment variables available to PHP code
; via getenv(), $_ENV and $_SERVER.
; Default Value: yes
;clear_env = no
; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
; the current environment.
; Default Value: clean env
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp
这篇关于如何让 PHP 能够读取系统环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何让 PHP 能够读取系统环境变量
基础教程推荐
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何替换eregi() 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
