apache SetEnv 设置

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']来进行调用和判断,这样在本地开发环境中不配置这个变量,在服务器上配置这个变量,可以写两份配置文件,判断这个变量的不同,从而调用不同的配置文件来进行开发.

原文地址:https://www.cnblogs.com/debmzhang/p/3374674.html