I've queried about this before, but I still don't get how to make this work.
I'm using Git and I've got a local development server and a production server.
If I use "SetEnv FUEL_ENV production" in .htaccess, I can't use oil.
How do you handle the environment?
tried all these combinations (and others) without success:
php oil r My_Task -env PRODUCTION
php oil r My_Task --env=production
php oil r My_Task -env production
php oil r --env production My_Task
php oil --env production r My_Task
php oil r -env PRODUCTION My_Task
?? What's the final syntax?!
I hope some day will have some great docs for this framework....
The command must be the first, followed by the what. Switches need an = sign if they have a parameter.
So this is the only correct one
php oil r My_Task --env=production (uppercase is ok too)
if I do a "php oil refine migrate --env=stage" I get the error that the staging DB can not by found (which is correct, it's not present on my dev system).
So the switch works, no question about it.
Environment support for Oil has been added on Dec. 21th 2011, so if you're FuelPHP version is older than that (the current 1.1 version was released on Dec. 13th) the switch is not supported.
Thanks a lot Harro for the quick reply.
But looks like it didn't solve my problem. I must run a CRON job on daily basis and I can't figure out why my task doesn't load the right config (it works well on the live website)
I know I'm on v1.1 (HEAD) on both core and packages/oil ....
When I do : php oil r Daily_Run --env=PRODUCTION
I get this error (which I don't get on my dev environments):
2013 - SQLSTATE[HY000] [2013] Lost connection to MySQL server at 'reading initial communication packet', system error: 110 in COREPATH/classes/database/pdo/connection.php on line 86
And effectively when I var_dump( \Config::get('db') ) it shows me the development config.......
I'll continue to investigate...
Hi,
I had to change, in the main bootstrap.php:
before:
Fuel::$env = ( isset($_SERVER) ? $_SERVER : Fuel::DEVELOPMENT ) ;
after:
Fuel::$env = ( isset($_SERVER) ? $_SERVER : Fuel::PRODUCTION ) ;
and now it works...
Anyway, we deploy on prod server using capistrano, so it was easy to set Fuel::PRODUCTION only on production servers.
thanks!
edit: what's that shitty emoticon it is trying to show?
The idea behind that is that you set the environment using SETENV, so you don't have to change your code when you move environments.
That line will only set a default, based on your OS environment setting, and falls back to Fuel::DEVELOPMENT when nothing is set. Oil's init runs after that, and that's where the processing of the --env parameter takes place, which should overwrite the value of Fuel::$env if defined.
Thats how it should work, and how it works here.
edit: there are bugs in the site css, but the creator doesn't seem to have time to fix it...
You mean oil on your production server doesn't pick up the correct environment?
I don't think Oil works that way (as the way you define it for your site doesn't work with oil), but it knows the "-env <environment>" commandline option, where (in this case) you should use "-env PRODUCTION". In capitals as it has to match the Fuel class constant being used.
Yeah, logically oil doesn't obviously go through Apache, so any changes made to .htaccess are not picked up. Thanks for the tip, I'll add it to the Docs.