Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SetEnv APPLICATION_ENV development - .htaccess interacting with Zend Framework?

I have the following on my htaccess.

SetEnv APPLICATION_ENV development

When I pass this file to prodution, I will change it to:

SetEnv APPLICATION_ENV production

This

development

and

production

are set on Zend Framework application.ini correct ?

How does Zend and Apache communicate here? How does Zend knows about that htaccess instruction?

Thanks.

like image 627
MEM Avatar asked Mar 27 '11 11:03

MEM


2 Answers

SetEnv, used in Apache's configuration (be it a .htaccess file, or a VirtualHost), defines an environment variable.

From PHP, you can read environment variables either :

  • using the getenv() function.
  • Or in the $_SERVER or $_ENV superglobal variables


Taking a look at the given index.php in Zend Frameworks QuickStart, you'll see it uses that environment variable the define the PHP constant called APPLICATION_ENV :

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV',
              (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV')
                                         : 'production'));

And that constant is later used to initialize the application :

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
like image 88
Pascal MARTIN Avatar answered Oct 18 '22 17:10

Pascal MARTIN


The flow of communication, as you call it, is the followoing:

If you use

SetEnv APPLICATION_ENV production

in your .htaccess, the environment you set there, will be used. Why?

The following piece of code from your index.php doesn't define the constant, if it has been defined already, which is the case, if you use SetEnv in your .htaccess.

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV',
              (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV')
                                         : 'production'));

If your .htaccess doesn't define the constant, the value provided in the index.php will be used. If I were you, I would still keep it in sync. Because you may make mistakes like forgetting to set AllowOverride for your vhost which would result in a situation where the environment is set by the index.php even though the .htaccess is present.

like image 40
markus Avatar answered Oct 18 '22 17:10

markus