M T
M T

Reputation: 4379

Laravel set environment variable

Trying to set the environment variable from commandline like

php artisan serve --env=someenv

But a var_dump(App::environment()) outputs string 'production' (length=10).

Shouldn't it be someenv ?

Upvotes: 0

Views: 4300

Answers (2)

Olav
Olav

Reputation: 1602

Laravel 5 can use a .env file in your installation base directory to determine your environment. For example, to set the current environment as the „local“ one, create a file .env with

APP_ENV = local

Please see another answer for more details on this mechanism.

Upvotes: 0

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

Reputation: 87719

This environment you set on php artisan seve is just for that particular command, running on cli.

Note that this is not you application running, just a webserver, provided by PHP so you don't need to install a full apache or nginx to test your application.

Your web application will run under a different environment and you still need to provide a correct environment adding it to your bootstrap/start.php file:

$env = $app->detectEnvironment(array(

    'local' => array('localhost', '127.0.0.1', 'example.com'),

));

Upvotes: 2

Related Questions