PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 5, 2022

[FIXED] How to change the environment in Laravel 5.1?

 November 05, 2022     environment-variables, laravel, php, production-environment, test-environments     No comments   

Issue

What I understand about the working of environments in Laravel is that you have different environments for different, well environments. So, if you are running your app locally you could have a .env.local file. If you are testing or on production, you could use .env.testing or .env.production. (Correct me if I am wrong.)
By default we get .env file that we can edit. But can anybody tell me what is the workflow of changing the environments in Laravel. I tried the documentation but I couldn't get it. Please help me.


Solution

When you install Laravel 5.1 you get two files .env and .env.example if you want to work locally you set :

APP_ENV=local
APP_DEBUG=true

in prod you set

APP_ENV=production
APP_DEBUG=false

An error message in debug mode

enter image description here

An error message from production mode

enter image description here

Note: you have two .env files .env and .env.example .. you can also create another one that you name .env.production but keep in mind that in order to get your configuration loaded you must just rename your file to .env

EDIT : So in case you are still working in local and you need another database for test, you can create another file so in total you have 3 .env files :

.env.production
.env.local1
.env.local2

whenever you want to switch configuration just rename the desired file to .env



Answered By - Mohamed Salem Lamiri
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,213,581

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing