开发者

Zend SetEnv in .htaccess not working

I installed Zend on my ubuntu homeserver. In my .htaccess file i have the followi开发者_Python百科ng code:

SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [NC,L]

When i echo APPLICATION_ENV in my index.php in the public folder, APPLICATION_ENV is not set.

What am i doing wrong?

Mod rewrite is enabled in apache.


In order to use SetEnv within a .htaccess file, I believe you need to set...

AllowOverride FileInfo

...within the relevant virtualhost directory block. (And then restart the httpd service as per usual.)

Additionally, depending on how you're running PHP, it's possible that such information is being stripped out. (e.g.: suexec will effectively remove all non-HTTP* environment vars.)


First You need mod_env installed (and mod_rewrite)

Double check if Apache has the module(s) loaded with either:

apachectl -l or httpd -l

the command might be different according to OS distribution i believe.

For the .htaccess file to work you need AllowOveride All which can be set in different configuration files (and "parts" depending on the way your OS as Apache configured. Your best option is to find out if it is a htaccess file issue or an environment one. Set anywhere in main configuration file:

SetEnv TESTME foobar

restart Apache and echo TEST from a PHP script. If you got it, debug the .htaccess

Note 1: Restrict in your virtual host the usage of .htacess to the folder where you really need it or move the configurations to a virtual host.

Note 2: You probably don't need all those rewrite rules if you have Apache mod_dir installed. Have a look at it


You can also use:

RewriteRule .* - [E=ENV_NAME_HERE:ENV_VALUE_HERE]


I prefer to put SetEnv in the httpd.conf file for the local server, so that all my local ZF apps run in development mode, and when I push to the staging server it has a flag to Set the environment to staging, then the production server has no such setting so it defaults to production...

This way I can keep the same .htaccess file in source control and when I push it out to the different servers it behaves as expected.

middaparka is right about suExec... suExec prevents you from setting custom environment variables in your .htaccess file - according to remi at the WebFaction forum.


If you are running your home server on a Mac or have suEXEC enabled, there are security measures in place to strip any non-http environment variables that are defined, therefore they won't appear in $_ENV['APPLICATION_ENV']. You CAN, however access these through a PHP function to get the same thing.

$var = apache_getenv('APPLICATION_ENV');

You could even define the environment variable within PHP if you want, although not recommended.

$_ENV['APPLICATION_ENV'] = apache_getenv('APPLICATION_ENV');

I have an almost identical config to what you have, and we just define a global:

define('APPLICATION_ENV', apache_getenv('APPLICATION_ENV'));

Once you do that, it should work as desired.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜