5. This snippet code, use, putenv php function to set APP_ENV and then using the Dotenv package by vlucas. I’m loading the file that we created and base on the .env file we can determine which environment should we use.

Hello, What version of php you’re using in your server now? Can you check from your phpinfo() if safe_mode_allowed_env_vars is enabled, if not you should enabled it. Also if safe_mode_allowed_env_vars is enabled and still not working.. try to use this apache_setenv or apache_getenv if you’re using apache. let me know if this help.

How do I setup multiple dev environments on a box(server) (I’d first implement it on a local laptop then transfer it to a server machine), so multiple developers Just need an SDK, set some config, and start coding. When done, they can just commit the code. The databases for dev vs prod are already set in the config?. I need such a laravel dev environment setup. All they have to do is modify hosts file. All Help is appreciated.

This tutorial can be used in your multiple dev environments.. if you have development and production you can easily separate them. just apply the current tutorial then the database will be separate for developement and for productions.

I had a couple of issues though, and I just want to share how I fixed them.

I’m using Laravel version 5.2.39 and I placed the environment.php file under /bootstrap/environment.php instead of app/bootstrap/environment.php because app/ and bootstrap/ folders are on the same level.

Then I had this error: “Fatal error: Call to a member function detectEnvironment() on a non-object in […]/bootstrap/environment.php on line 13″

To fix it, I had to add the following code in app/bootstrap/environment.php, just above the line that calls detectEnvironment()

Why are people insisting on having more than one .env file? :-/
IMO – There should only be one Environment Setup per environment.
Staging server should be separate, and in that case just has a .env file with its own settings.
Local server, separate again, where the .env file is its own copy, with its own settings.
Each developer sets their own settings on their DEV machines. e.g. my DB username and password can be different to all other developers on my team. My own local environment settings will not affect the app.
The staging server should _not_ contain a copy of the production server’s environment settings file. Nor should any of your repositories. Keep it on one server, secure, restricted access.
… just my thoughts.

Yes, you have a point.. well its really depend on each developer.. but remember we’re doing this to separate things.. for local and productions whereas the productions .env is inside of my .gitignore. so from production server it will not get pulled out from the repositories. and each developer will create their own .local.env files… this setup is most likely used in a Single Server setup.. coz some company or developer cant afford to have different environment server.. thats my opinion only..