Zend SetEnv in .htaccess not working

前端 未结 5 1348
有刺的猬
有刺的猬 2021-02-08 05:07

I installed Zend on my ubuntu homeserver. In my .htaccess file i have the following code:

SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQU         


        
相关标签:
5条回答
  • 2021-02-08 05:29

    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 讨论(0)
  • 2021-02-08 05:41

    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.

    0 讨论(0)
  • 2021-02-08 05:46

    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.)

    0 讨论(0)
  • 2021-02-08 05:48

    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

    0 讨论(0)
  • 2021-02-08 05:50

    You can also use:

    RewriteRule .* - [E=ENV_NAME_HERE:ENV_VALUE_HERE]
    
    0 讨论(0)
提交回复
热议问题