The standard practice for setting the environment (production/staging/development) with the Zend Framework is using SetEnv
in the Apache config (or .htaccess
) to set the APPLICATION_ENV
. This obviously works well for web requests, but what about running command line scripts (that are still part of the application, using the same bootstrapping, and rely on the correct APPLICATION_ENV
)?
Any best practices for that? Right now I'm just dropping a .environment.php
file in my cli
directory - it's included if it exists (similar to .htaccess
I guess), and can be used to set the environment.
For (linux)command-line only usage you could add following line to your ~/.bashrc
export APPLICATION_ENV=development
Or add the line to /etc/profile
to set the environment variable for all users.
For more information:
Cron uses a clean/empty environment and doesn't look at /etc/profile
or ~/.bashrc
for the APPLICATION_ENV or other environment variables.
Just define the environment variable inside the crontab:
APPLICATION_ENV=development
0 0 * * * /usr/bin/php /path/to/your_script.php
For more information:
You can also run the script
APPLICATION_ENV="local" php cli.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With