Demand
在PHP开发中为了区分线上生产环境还是本地开发环境,如果我们能通过判断$_SERVER['RUNTIME_ENVIROMENT']为 'DEV'还是'PRO'来区分该多好,可惜的是$_SERVER数组里面根本没有RUNTIME_ENVIROMENT这个元素。
First, through the Nginx Fastcgi_param to set
In the Nginx configuration file, it can be set in the Nginx profile nginx.conf, or in a separate site configuration environment, such as: www.tomener.com.conf
Add the appropriate configuration information in the Configure Environment Server segment location:
location ~ \.php($|/) { try_files $uri =404; fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param RUNTIME_ENVIROMENT 'PRO'; # PRO or DEV}
Here only added Fastcgi_param runtime_enviroment ' PRO ' a value, more can be added in the back
Then reboot and restart Nginx.
nginx -s reload
Second, through the PHP main configuration file php-fpm.conf to set
This setting must be placed in the main configuration file php-fpm.conf, can not be placed in the include directive settings sub-configuration file, or will be error: "array is not allowed in the global section"
My php-fpm.conf position is in/usr/local/php/etc/php-fpm.conf.
Add directly to the configuration file:
env[RUNTIME_ENVIROMENT] = 'PRO'
Restart PHP-FPM after adding
service restart php-fpm
After adding the $_server variable value in the above 2 ways, we can get the corresponding variable value directly in the PHP file by $_server.
However, it is said that the configuration information through the Nginx Fastcgi_param to set, when Nginx and PHP interaction, will bring a lot of data transfer.
Apache Set Environment variables
SetEnv 变量名 变量值
ServerAdmin webmaster@demo.com DocumentRoot "e:\wwwroot\demo" ServerName my.demo.com ErrorLog "logs/my.demo.com-error.log" CustomLog "logs/my.demo.com-access.log" common SetEnv RUNTIME_ENVIROMENT DEV
Options Indexes FollowSymLinks AllowOverride All Require all granted
Reference Documentation:
http://man.chinaunix.net/newsoft/ApacheManual/mod/mod_env.html#setenv
The above describes the Apache/nginx for PHP settings, add $_server server environment variables, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.