Tim Lytle
Tim Lytle

Reputation: 17624

Setting Zend APPLICATION_ENV for Command Line Scripts

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.

Upvotes: 15

Views: 5326

Answers (2)

Bob Fanger
Bob Fanger

Reputation: 29897

From a terminal

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:

From a crontab

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:

Upvotes: 17

Arun Killu
Arun Killu

Reputation: 14233

You can also run the script

APPLICATION_ENV="local" php cli.php

Upvotes: 1

Related Questions