I want to know what environments Laravel supports by default. I know that "production" and "local" are two available, but there's no other? And if so, how does it alter the behavior of logging.
Another thing is that I believe that I declare one custom environment, it will cause any unexpected behavior?.
Thanks!
Before loading your application's environment variables, Laravel determines if either the APP_ENV environment variable has been externally provided or if the --env CLI argument has been specified. If so, Laravel will attempt to load an .env. [APP_ENV] file if it exists. If it does not exist, the default .env file will be loaded.
Laravel's default .env file contains some common configuration values that may differ based on whether your application is running locally or on a production web server. These values are then retrieved from various Laravel configuration files within the config directory using Laravel's env function.
To sample a basic selection of Laravel features, we will build a simple task list we can use to track all of the tasks we want to accomplish (the typical "to-do list" example). The complete, finished source code for this project is available on GitHub. Of course, first you will need a fresh installation of the Laravel framework.
All of the configuration files for the Laravel framework are stored in the config directory. Each option is documented, so feel free to look through the files and get familiar with the options available to you.
The only values that mean anything to the framework are production
, testing
, and local
.
When your environment is production
, this just adds a little extra protection to some artisan commands (e.g. migrating, seeding). When in production
, these commands must be run with the --force
option.
When your environment is testing
, this makes App::runningUnitTests()
return true
. This is used to disable verifying CSRF tokens when running phpunit tests. The default phpunit.xml
file in Laravel sets the environment to testing
.
When your environment is local
, this makes App::isLocal()
return true
. This function is not actually used anywhere, unless you've used it yourself.
As you can see, you're free to set the environment value to whatever you want, with minimal consequences. If you don't use production
, it is slightly easier to accidentally run a damaging artisan command you didn't want. If you don't use testing
, you might have an issue with CSRF tokens with your phpunit feature tests. If you don't use local
, this will only affect you if you already have custom code that depends on the local
environment.
One other side note regarding the environment: as of Laravel 5.2.13, you can have different .env
files for different environments. Laravel will first look for the .env.{environment}
file, and if it doesn't exist, will then just load the default .env
file.
So, for example, you could create a .env.testing
file that will be used by your phpunit tests (since they use the testing
environment), and it could live right next to your .env
or .env.local
file that is used when you're developing or manually testing the site.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With