Laravel Configuration Process


Laravel Configuration Process – Here we are going to explain how to configuration laravel.


Laravel Configuration Process.

Let us understand how to configure laravel.

Functions:-

There are some followings process to configure laravel.

  • 1. Introduction.
  • 2. Environment configuration.
  • 3. Accessing configuration values.
  • 4. Configuration caching.
  • 5. Maintenance mode.

1. Introduction.

All of the configuration file for the laravel framework are stored in the config directory. Each option is documented, so feel free to look through the file and get familiar with the options available to you.

2. Environment configuration.

It is many time helpful to have different configuration values based on the enviroment where the application is running. For example, you may wish to use a different cache diver locally than you do on your production server.

Laravel use the DotEnv PHP library. In a fresh Laravel installation, the root directory of your application will contain a .env.example file. If you install Laravel via composer, this file will automatically be renamed to .env. otherwise you should rename the file manually

Retrieving Environment Configuration

all the variables listed in this file will be loaded into the $_ENV PHP super global when your application recieve a request. Yet, you may use the env helper to retrieve values from these variables in your configuration files

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

Determining The Current Environment

the current application enviroment is determined via the APP_ENV variable from your .env file.
You may access this value via the enviroment method on the app.

$environment = App::environment();

You may also pass arguments to the enviroment method to check if teh enviroment matches a given value.
the method will return true if the enviroment matches any of the given values:

if (App::environment('local')) 
{
    // The environment is local.
}

if (App::environment('local', 'staging')) 
{
    // The environment is either local OR staging.
}

3. Accessing configuration values.

The configuration values may be accessed using “dot” syntax, which include the name of the file and option you wish to access. A default value may also be specified and will be returned if the configuration option does not exit.

$value = config('app.timezone');

To set configuration value at runtime, pass an array to the config helper.

config(['app.timezone' => 'America/Chicago']);

4. Configuration caching.

To give your application a speed boost, you should cache all of your configuration files into a single file using the config:cache Artisan command. This will combine all of the configuration option for your application into a single file which will be loaded quickly by the framework.

You should typically run the php artisan config:cache command as part of your production deployment routine.

5. Maintenance mode.

When your application is in maintenance mode, a custom view will be displayed for all requests into your application. This makes it easy to “disable” your application while it is updating or when you are performing maintenance. A maintenance mode check is included in the default middleware stack for your application. If the application is in maintenance mode, a MaintenanceModeException will be thrown with a status code of 503.

To enable maintenance mode, simply execute the down Artisan command:

php artisan down

You may also provide message and retry options to the down command.

php artisan down --message="Upgrading Database" --retry=60

To disable maintenance mode, use the up command.

php artisan up

Maintenance Mode Response Template.

The default template for maintenance mode responses is located in resources/views/errors/503.blade.php.
You are free to modify this view as needed for your application.

Maintenance Mode & Queues.

While your application is in maintenance mode, no queuedjobs will be handled. The jobs will continue to be handled as normal once the application is out of maintenance mode.

Alternatives To Maintenance Mode.

Since maintenance mode requires your application to have several seconds of downtime, consider alternatives like Envoyer to accomplish zero downtime deployment with Laravel.


Advertisements

Add Comment

📖 Read More