Answer the question
In order to leave comments, you need to log in
Testing, staging, production and Zend Framework?
What is the best/easiest way to switch settings on different environments?
Upd: Zend documentation advises APPLICATION_ENV.
Answer the question
In order to leave comments, you need to log in
To store the name of the environment, use an environment variable, as said here. For example "APPLICATION_ENV".
To determine the environment environment, you can use the following algorithm:
$test_domain = 'testsite.ru'; // домен тестового сервера
if(strpos($_SERVER['HTTP_HOST'], $test_domain) !== FALSE) {
$app_env = 'test';
} else {
$app_env = ($_SERVER['REMOTE_ADDR'] == $_SERVER['SERVER_ADDR']) ? 'development' : 'production';
}
define('APPLICATION_ENV', $app_env ? $app_env : 'production');
public static function isUnderUnitTest()
{
return $_SERVER['PHP_SELF'] === '/usr/bin/phpunit';
}
Zend advises this for a reason, the calculation here is that you correctly (according to Zend's advice) set up virtual hosts, such as Apache. Then the code will be universal, and without hardcoded domain names. This is how it looks like (ZendTool also creates something similar):
<VirtualHost hostname.local:80>
ServerAdmin [email protected]
SetEnv APPLICATION_ENV "development"
ServerName hostname.local
DocumentRoot /home/hostname.local/htdocs
<Directory />
Options FollowSymLinks
</Directory>
<Directory /home/hostname.local/htdocs/>
Options Indexes FollowSymLinks MultiViews
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel warn
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question