Laravel 5 How to switch from Production mode

PhpLaravelLaravel Artisan

Php Problem Overview


When I run $ php artisan env I get;

Current application environment: production

How can I change this to development or something similar? So I can see errors.. I have read a lot of the documentation but it is not at all easy for a newbie to understand. I don't have server config experience, really.

I'm sure there is "smart" way to do this, but all I am interested in, for now, is manually changing the environment. How do I do this?

Php Solutions


Solution 1 - Php

Laravel 5 gets its enviroment related variables from the .env file located in the root of your project. You just need to set APP_ENV to whatever you want, for example:

APP_ENV=development

This is used to identify the current enviroment. If you want to display errors, you'll need to enable debug mode in the same file:

APP_DEBUG=true

The role of the .env file is to allow you to have different settings depending on which machine you are running your application. So on your production server, the .env file settings would be different from your local development enviroment.

Solution 2 - Php

Laravel 5 uses .env file to configure your app. .env should not be committed on your repository, like github or bitbucket. On your local environment your .env will look like the following:

# .env
APP_ENV=local

For your production server, you might have the following config:

# .env
APP_ENV=production

Solution 3 - Php

Do not forget to run the command php artisan config:clear after you have made the changes to the .env file. Done this again php artisan env, which will return the correct version.

Solution 4 - Php

What you could also have a look at is the exposed method Application->loadEnvironmentFrom($file)

I needed one application to run on multiple subdomains. So in bootstrap/app.php I added something like:

$envFile = '.env';
// change $envFile conditionally here
$app->loadEnvironmentFrom($envFile);

Solution 5 - Php

In Laravel the default environment is always production.

What you need to do is to specify correct hostname in bootstrap/start.php for your enviroments eg.:

/*
|--------------------------------------------------------------------------
| Detect The Application Environment
|--------------------------------------------------------------------------
|
| Laravel takes a dead simple approach to your application environments
| so you can just specify a machine name for the host that matches a
| given environment, then we will automatically detect it for you.
|
*/

$env = $app->detectEnvironment(array(
	'local' => array('homestead'),
    'profile_1' => array('hostname_for_profile_1')
));

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmikelovelyukView Question on Stackoverflow
Solution 1 - PhpBogdanView Answer on Stackoverflow
Solution 2 - PhpNino PaoloView Answer on Stackoverflow
Solution 3 - PhpSergio PaivaView Answer on Stackoverflow
Solution 4 - PhpSjeitiView Answer on Stackoverflow
Solution 5 - PhpMarcin ŁojewskiView Answer on Stackoverflow