Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set env with laravel artisan to have two different database connections (local/remote)?

I looking for setup a multi-environment project using Laravel3 but I dont understand the command to set the environment.

I see here: http://laravel.com/docs/artisan/commands The command is:

php artisan foo --env=local

I already used artisan and bob with success, what I can't undertand the foo, I try to change to my project name but always the same output: "Sorry, I can't find that task."

If I try: php artisan --env=local

That will return: "You forgot to provide the task name."

Anybody can help? Thanks for your time.

[edit] With the answers now I can understand better and improve my question:

I have a project with those folders created: http://d.pr/i/5nZS With that in mind, I need to set my local env as development and production as production. So, I can do that with any variation of the command "php artisan --env=local" or I need to add on my public/.htaccess "SetEnv LARAVEL_ENV development"?

Thanks again.

like image 775
Lucas Serafim Avatar asked Jan 15 '13 17:01

Lucas Serafim


2 Answers

"Foo" is whatever command you want to run. E.g. for migrations:

php artisan migrate --env=local

Another thing you can do is add your computers hostname to this array

For example, if my local computer name is 'Effinity.local' I could do

$environments = array(
    'local' => array('http://localhost*', 'Effinity.local'),
);

Then you do not need to specify the environment, just:

php artisan migrate

Hope that helps.

like image 63
William Cahill-Manley Avatar answered Oct 14 '22 21:10

William Cahill-Manley


Here, how I solved my question:

First I didn't need the command php artisan migrate --env=local, I just need set on my virtualhost: SetEnv LARAVEL_ENV development.

Second, as William Cahill-Manley say, I need to work on application/paths.php, the $environments. I've used it before but the wrong way. In my case, I solve with that:

$environments = array(
    'development' => array('http://localhost/project*', '*project/*'),
    'production' => array('http://project.com', 'http://*.project.com')
);

My problem was because my code before was like that:

$environments = array(
    'development' => array('http://localhost/project*', '*project*'),
    'production' => array('http://project.com', 'http://*.project.com')
);

And because the second element of development array, in the production server always will be in development. Thats because the url on development be http://project/ and on production be http://project.com/ or http://user.project.com/

See, the project will force in all envonriments be development by the asterisk/wildcard.

like image 20
Lucas Serafim Avatar answered Oct 14 '22 20:10

Lucas Serafim