php的服務器預定義變量 $_SERVER
可以通過apache的mod_env模塊來添加我們所需要的內容
來段官網介紹
Description: | Modifies the environment which is passed to CGI scripts and SSI pages |
---|---|
Status: | Base |
Module Identifier: | env_module |
Source File: | mod_env.c |
Summary
This module allows for control of internal environment variables that are used by various Apache HTTP Server modules. These variables are also provided to CGI scripts as native system environment variables, and available for use in SSI pages. Environment variables may be passed from the shell which invoked the httpd
process. Alternatively, environment variables may be set or unset within the configuration process.
可以通過 SetEnv來向apache虛擬主機配置文件里寫一些我們需要的東西
對setenv來段官網介紹
Description: | Sets environment variables |
---|---|
Syntax: | SetEnv env-variable [value] |
Context: | server config, virtual host, directory, .htaccess |
Override: | FileInfo |
Status: | Base |
Module: | mod_env |
Sets an internal environment variable, which is then available to Apache HTTP Server modules, and passed on to CGI scripts and SSI pages.
Example
SetEnv SPECIAL_PATH /foo/bin
If you omit the value argument, the variable is set to an empty string.
來段配置實例
<VirtualHost *:80>
ServerName aa.com
DocumentRoot /var/www
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteCond %{HTTP_HOST} !^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css|xml|swf|cur|html|apk|manifest)$ /index.php
</IfModule>
SetEnv RUN_MODE production
</VirtualHost>
就是紅色部分了,可以在php里使用$_SERVER['RUN_MODE']來進行調用和判斷,這樣在本地開發環境中不配置這個變量,在服務器上配置這個變量,可以寫兩份配置文件,判斷這個變量的不同,從而調用不同的配置文件來進行開發.