Laravel Configuration

In this tutorial you will learn about the Laravel Configuration and its application with practical example.

The config directory contains all of your application’s configuration files.

Directory Permissions

After installing Laravel it is required to set the write permission for the storage and bootstrap/cache directory otherwise laravel will not work.

Application configuration

The application configuration information is located in /config/app.php. You can set or change various parameters for your application from here.

Debugging mode

Locate the following code

From here you can set debug mode.

Time zone
Locate the following code

From here you can set your preferred time zone, default is UTC

Application Key

Locate the following code

from here you can set encryption key for your application, it required to generate application key for security purpose.

Environmental Configuration

After installing Laravel; .env file is automatically created in root directory of your application. If it is not created; simply rename the .env.example file to .env file. This file contains various environment variables for your application.

Your .env file should resemble something similar to this.

Note: The first line in the above code snippet APP_ENV=local has been set. It can further be changed to production or testing as per your requirement.

Authentication configuration

The authentication configuration file is located in /config/auth.php, you can change it as per your application requirements.

Database configuration

The database configuration file is located in /config/database.php. In this file you can set different parameters for database, based on the database engine you are using. Below is configuration code for MySQL Database –

Replace <host-name>, <database-name>, <user-name> and <password> with your hostname, database name, username and password correspondingly.

Naming the Application

The default namespace for laravel application is App; but if you want to change it to match your application name, which can be easily done using app:name Artisan command.

Replace <application-name> with the application name of your choice.

Maintenance Mode

Sometimes, you may need to put your application into maintenance mode for upgrades. This will make your application temporarily unavailable for public access. You don’t want errors to pop up when you are going through the important updates in the background, right?
Laravel made it easier for you, there are artisan commands available to start and stop the maintenance without any hassle.

Command to start Laravel Maintenance Mode

To put application into maintenance mode, execute the following command.

Command to stop Laravel Maintenance Mode

Once you are done with upgrading application or making changes to it and want to make it live again, execute the following command.

There is a default template for maintenance mode is located in resources/views/errors/503.blade.php. You are free to customize it as per your application requirement.

 

In this tutorial we have learn about the Laravel Configuration and its application with practical example. I hope you will like this tutorial.