Configuring the Laravel 5 environment

Laravel, Laravel 5, 2015-06-17 00:02:37 UTC

This topic is quite interesting. Because you must not skip configuring you application when you develop with Laravel.

Before I wrote this tutorial, I do research on this topic. I just found a little tutorial and the tutorials are not easy to understand.

So I write this tutorial. Then you can set your Laravel 5 environment in just 3 steps.

1. Open your Laravel 5 root folder. Please find a file ".env.example". If you don't find it, please make sure your folder configuration is showing hidden file.

2. Copy and rename into ".env"

$ cp .env.example .env

3. Open ".env" file and make a change according to your environment.




I assume you try this tutorial on your local machine. When you push your file into the repository, make sure don't not commit ".env" file. You certainly don't want people see this configuration or the production server use this configuration.

I quote from the developer in His GitHub repository file;

phpdotenv is made for development environments, and generally should not be used in production. In production, the actual environment variables should be set so that there is no overhead of loading the .env file on each request. This can be achieved via an automated deployment process with tools like Vagrant, chef, or Puppet, or can be set manually with cloud hosts like Pagodabox and Heroku.

So, in the production server, you don't need to create ".env" file. Application will choose the default configuration in "app_root/app/config" folder.

All variables that you find in ".env" file is related to the array key-value that you have found in "app_root/configuration/*" file which use env() function.

For example, open "app_root/configuration/app.php" file, you can see like below

return [
    'debug' => env('APP_DEBUG'),
    'url' => 'http://localhost',
    'timezone' => 'UTC',
    'locale' => 'en',
    'fallback_locale' => 'en',
    'key' => env('APP_KEY', 'SomeRandomString'),
    'cipher' => MCRYPT_RIJNDAEL_128,
    'log' => 'daily',

This is similiar to ".env" variables; APP_DEBUG, APP_KEY

So, when you have ".env" file in your root application, ".env" variables will override all of your array value related to array key that the application found at ".env". If you don't have ".env" file, the application use all of the configuration in "app_root/config" folder.

And if you still want to configure it manually for one-time purpose in you production server, simple set something like this;

'debug' => env('APP_DEBUG',true),

Thats it :)