Introduction
All of the Laravel framework’s configuration files are stored in theconfig/ directory. Each option is documented with comments, so open the files and take a look at the available options.
Configuration files manage a variety of core settings such as database connection information, mail server information, application URL, and encryption keys.
The about command
Use the about Artisan command to see an overview of your application’s configuration, drivers, and environment.
--only option.
config:show is handy.
Environment configuration (.env)
It’s common to want configuration values to differ based on the environment your application is running in. For example, you may want to use a different cache driver locally than in production. Laravel makes this easy by leveraging the DotEnv PHP library. On a fresh installation, the root directory contains a.env.example file with common environment variables, and it’s automatically copied to .env during installation.
When developing as a team, it’s convenient to keep the
.env.example file up to date and commit it to the repository. Setting placeholder values makes it clear to other developers on the team which environment variables they need.Environment file security
However, Laravel has a built-in feature for encrypting your environment file, which allows you to safely commit it to source control in an encrypted form.Additional environment files
When starting up, Laravel checks whether theAPP_ENV environment variable or the CLI --env argument is set. If it is, and a .env.[APP_ENV] file exists, Laravel loads it. Otherwise, the default .env file is used.
Environment variable types
All variables in your.env file are parsed as strings, but the following special values are provided so env() can return a broader set of types.
To define a value that contains a space, wrap it in double quotes.
Retrieving environment variables
All the variables listed in your.env file are loaded into the PHP $_ENV super-global when a request is received. Inside configuration files, use the env() function to retrieve values.
Determining the current environment
The current environment is determined by theAPP_ENV variable in your .env file. You can retrieve it via the environment method on the App facade.
Encrypting environment files
Unencrypted environment files should not be stored in source control, but Laravel provides functionality to encrypt them..env is encrypted and the encrypted contents are saved to a .env.encrypted file. The decryption key is printed in the command’s output, so store it in a secure password manager.
To decrypt, use the env:decrypt command.
Accessing configuration values
You can access configuration values from anywhere in your application using theConfig facade or the global config() function. Use “dot” notation to combine the file name and the option name.
Config::set() or pass an array to config().
Caching configuration
To improve your application’s performance, cache all configuration files into a single file..env file is no longer loaded during framework requests or Artisan command execution. That means env() returns only system-level environment variables.
To remove the cache, use the config:clear command.
Publishing configuration files
Most of Laravel’s configuration files are already published in theconfig/ directory, but some files like cors.php and view.php are not published by default.
Use the config:publish command to publish unpublished configuration files.
Debug mode
Thedebug option in config/app.php determines how much error information is actually shown to the user. By default, this option follows the value of the APP_DEBUG environment variable in your .env file.
Maintenance mode
When your application is in maintenance mode, a custom view is displayed for all requests. This makes it easy to “disable” your application temporarily while it is updating or when you’re performing maintenance.Enabling maintenance mode
--refresh option, the browser will automatically reload after the specified number of seconds.
--retry option is set as the value of the Retry-After HTTP header.
Bypassing maintenance mode
To allow only specific users to access using a secret token, use the--secret option.
--with-secret option to have Laravel generate a token for you.
Maintenance mode across multiple servers
By default, Laravel manages maintenance mode via a file. For a multi-server setup, a cache-based approach is more convenient.Pre-rendering the maintenance view
If you runphp artisan down during a deployment, users who access your application while dependencies are being updated may see errors. To avoid this, pre-render the view with the --render option.
Disabling maintenance mode
You can customize the default maintenance mode template by creating
resources/views/errors/503.blade.php.Next steps
Routing
Learn the basics of routing that connects URLs to controllers.