A common place to set environment variables is to distinguish between development environment/production environment, or to define some database accounts and passwords
Set Apache environment variables
Command
Set the current environment variable to DEV
SetEnv RUNTIME_ENVIROMENT DEV
Database account password
SetEnv MYSQL_USERNAME root
SetEnv 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 VirtualHost> Set Nginx environment variable Command Set the current environment variable to DEV fastcgi_param RUNTIME_ENVIROMENT 'DEV' Database account password fastcgi_param MYSQL_USERNAME 'root' fastcgi_param MYSQL_PASSWORD 'root' Configuration file format Configured in the fastcgi_params file fastcgi_param RUNTIME_ENVIROMENT 'DEV'; fastcgi_param MYSQL_USERNAME 'root'; fastcgi _param MYSQL_PASSWORD 'root'; Configure in nginx.conf Set environment variables for PHP scripts Temporary settings for the current user Temporary settings only need to be executed export KEY=VALUE is current Permanent user settings Write in ~/.bashrc (different systems vary) Set for all users (excluding root) Create the file /etc/profile.d/test.sh and write Set Key = Value Sometimes PHP scripts are controlled by Supervisor, so remember to set the environment item in the supervisor configuration There is also a super global variable method: server {
listen 80;
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;
}
}