Setting environment variables common places to differentiate a development environment/production environment, or to define account passwords for some databases
Setting Apache Environment variables
Instructions
Sets the current environment variable toDEV
SETENV runtime_enviroment DEV
Database account password
SetEnv mysql_username rootsetenv Mysql_password Root
Configuration file format
ServerAdmin admin@admin.com documentroot "/var/www/" ServerName localhost SetEnv runtime_enviroment DEV SETENV mysql_username Root SETENV Mysql_password root errorlog "Logs/error.log" customlog "Logs/access.log" common
Setting Nginx Environment variables
Instructions
Sets the current environment variable toDEV
Fastcgi_param runtime_enviroment ' DEV '
Database account password
Fastcgi_param mysql_username ' root ' fastcgi_param mysql_password ' root '
Configuration file format
Configuring in the Fastcgi_params file
Fastcgi_param runtime_enviroment ' DEV '; fastcgi_param mysql_username ' root '; Fastcgi_param mysql_password ' root ';
Configuring in Nginx.conf
server { listen ; root/var/www; Index index.php; server_name localhost; Location/ { index index.php; } Location ~. *\. (PHP|PHP5) $ { Fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; Include Fastcgi_params; } }
Setting environment variables for PHP scripts
Temporarily set for the current user
Temporary settings only need to be performed
Export Key=value
Permanently set for the current user
~/.bashrc
written in (different systems vary)
Set for all users (not including root)
Create /etc/profile.d/test.sh
a file, write
Key=value
Set for all users (including root)
In the /etc/environment
write
Key=value
Note that this file's effective time is when the user logs in, so for root, the machine needs to be restarted
Set in supervisor
Sometimes PHP scripts are controlled with supervisor, so remember to set the environment in the supervisor configuration
Invoking server environment variables in PHP
There are two ways to call in PHP:
$env = getenv (' runtime_enviroment ');
There are also hyper-global variable modes:
$env = $_server[' runtime_enviroment ');
The above describes the settings for PHP server Apache/nginx environment variables, including the apache,nginx aspects of the content, I hope that the PHP tutorial interested in a friend helpful.