两种方式
1、通过nginx的fastcgi_param来设置
在nginx配置文件中,可以在nginx总体的配置文件nginx.conf中,也可以在单独的网站配置环境中进行设置,如:www.test.com.conf
在配置环境段location中添加相应的配置信息:
location ~ .*\.(php|php5)?$
{
try_files $uri =404;
fastcgi_pass :/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
fastcgi_param DB_NAME 'testdb';
}
这里只添加了fastcgi_param DB_NAME ‘testdb’;一个值。
添加后重启nginx;
2、通过php主配置文件php-fpm.conf来设置
这个设置必须放在主配置文件php-fpm.conf里,不能放到include指令设置的子配置文件里,否则会报错:「Array are not allowed in the global section」
直接在配置文件中添加:
env[DB_NAME] = testdb
php读取
<?php
echo $_SERVER['DB_NAME ']
网友回复