70

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?

mikelovelyuk
  • 4,042
  • 9
  • 49
  • 95

5 Answers5

106

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.

Bogdan
  • 43,166
  • 12
  • 128
  • 129
  • So each server/environment has it's own `.env` file? Is that right? – mikelovelyuk Feb 25 '15 at 14:05
  • 13
    You have one `.env` file, but the contents can differ on each machine you run the application. For example on your local machine you would have `APP_ENV=development` and `APP_DEBUG=true`, but on your production server the values would be `APP_ENV=production` and `APP_DEBUG=false`. – Bogdan Feb 25 '15 at 14:35
  • So yeah, each server/environment has it's own `.env` file. – Bogdan Feb 25 '15 at 14:46
  • @Bogdan In the case I use Composer, should I let the vendor folder in a production environment after set APP_ENV=production ? – w3spi Sep 16 '15 at 22:09
  • @Zl3n Are you asking if you should deploy the `vendor` folder with the rest of your app or run a `composer install` on the production server? – Bogdan Sep 16 '15 at 22:18
  • @Bogdan Thank you for your quick answer ! So, use composer in local and deploy the whole project via FTP transfert (I haven't the rights to run composer on the server) – w3spi Sep 16 '15 at 22:19
  • @Zl3n Yes, you can upload the whole project with no worries. – Bogdan Sep 16 '15 at 22:50
  • ... and yet, I have a .env in the root of my project with `APP_ENV=local` and yet `php artisan env` still tell me I'm in production mode..? – Inigo Dec 28 '16 at 17:30
53

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
paolooo
  • 4,133
  • 2
  • 18
  • 33
40

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.

Sergio Paiva
  • 501
  • 4
  • 3
  • this will help anyone who find that the local server is trying to use `env.testing` after they have run tests – ohhh Aug 31 '18 at 10:56
6

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);
Sjeiti
  • 2,468
  • 1
  • 31
  • 33
-3

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')
));
  • 4
    The question is for Laravel 5. Your solution is for Laravel 4. In L5 there's no `bootstrap/start.php` file anymore. – Bogdan Feb 25 '15 at 13:35