: This article describes how to set and add $ _ SERVER environment variables for apacheng.pdf for PHP. For more information about PHP tutorials, see. Requirement
In PHP development, to distinguish between online production environments and local development environments, if we can identify how good it is by judging whether $ _ SERVER ['runtime _ ENVIROMENT '] is 'dev' or 'pro, unfortunately, the $ _ SERVER array does not contain the RUNTIME_ENVIROMENT element.
I. set it through fastcgi_param of nginx
In the nginx configuration file, you can either set it in the nginx configuration file nginx. conf or in a separate website configuration environment, such as www.tomener.com. conf.
Add the corresponding configuration information in the server segment location of the configuration environment:
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}
Only fastcgi_param RUNTIME_ENVIROMENT 'pro' is added here. more values can be added later.
Restart nginx
nginx -s reload
2. set through the php main configuration file php-fpm.conf
This setting must be placed in the php-fpm.conf of the main configuration file and not in the sub-configuration file set of the include command; otherwise, an error will be reported: "Array are not allowed in the global section 」
My php-fpm.conf location in/usr/local/php/etc/php-fpm.conf
Add the following 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 two ways, we can directly get the corresponding variable value through $ _ SERVER in the PHP file.
However, it is said that the configuration information is set through fastcgi_param of nginx. when nginx interacts with php, a large amount of data is transmitted.
Set environment variables in Apache
SetEnv variable name variable value
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:
http://man.chinaunix.net/newsoft/ApacheManual/mod/mod_env.html#setenv
The preceding section describes how to set and add $ _ SERVER environment variables for PHP in Apache/Nginx, including related content. if you are interested in PHP Tutorial.