MWZ

MINDWAREZONE

Laravel Configuration Files

Laravel configuration files are one of the most important parts of a Laravel application. They control how your application behaves, connects to services, stores data, sends emails, manages caching, and much more.

Think of configuration files as the control panel of your Laravel application.

Instead of hardcoding settings throughout your project, Laravel keeps them organized inside the config directory.

What Are Laravel Configuration Files?

Configuration files are PHP files that contain application settings.

directory.

config/
 ├── app.php
 ├── auth.php
 ├── cache.php
 ├── database.php
 ├── filesystems.php
 ├── logging.php
 ├── mail.php
 ├── queue.php
 ├── services.php
 ├── session.php

Each file controls a specific feature of Laravel.

Why Configuration Files Matter

Without configuration files, you would need to manually define settings throughout your application.

For example:

Instead of writing:

$databaseHost = '127.0.0.1';

everywhere, Laravel centralizes settings in:

config/database.php

Benefits:

  • Easy maintenance
  • Better organization
  • Environment-specific settings
  • Improved security
  • Cleaner code

How Configuration Files Work

Most configuration values come from the .env file.

Example .env:

APP_NAME="My Store"
APP_DEBUG=true
            

Inside config/app.php:

'name' => env('APP_NAME', 'Laravel'),
'debug' => env('APP_DEBUG', false),
            

Laravel reads values from .env and loads them into configuration files.

Accessing Configuration Values

Laravel provides the config() helper.

Example:

config('app.name');
            

Output:

My Store

Another example:

config('app.timezone');
            

Output:

UTC

Structure of a Configuration File

Example from config/app.php:

return [

    'name' => env('APP_NAME', 'Laravel'),

    'env' => env('APP_ENV', 'production'),

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

];
            

Configuration files return an array of settings.

config/app.php

This is Laravel's primary configuration file.

Location:

config/app.php
            

Controls:

  • Application name
  • Environment
  • Debug mode
  • URL
  • Timezone
  • Locale

Application Name

'name' => env('APP_NAME', 'Laravel'),
            

Reads:

APP_NAME="My Store"
            

Usage:

config('app.name');
            

Environment

'env' => env('APP_ENV', 'production'),
            

Possible values:

APP_ENV=local
APP_ENV=production
APP_ENV=staging
            

Usage:

app()->environment();
            

Debug Mode

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

Development:

APP_DEBUG=true
            

Production:

APP_DEBUG=false
            

Timezone

'timezone' => 'UTC',
            

Example:

'timezone' => 'Asia/Kolkata',
            

Laravel dates will use Indian Standard Time.

Locale

'locale' => 'en',
            

Used for translations.

Example:

'locale' => 'fr'
            

French language support.

config/database.php

Controls database connections.

Location:

config/database.php

MySQL Configuration

'mysql' => [

    'host' => env('DB_HOST'),

    'port' => env('DB_PORT'),

    'database' => env('DB_DATABASE'),

    'username' => env('DB_USERNAME'),

    'password' => env('DB_PASSWORD'),

],
            

Values come from:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=root
DB_PASSWORD=password
            

Default Database

'default' => env('DB_CONNECTION', 'sqlite'),
            

Example:

Laravel will use MySQL by default.

config/cache.php

Controls application caching.

Location:

config/cache.php

Example:

'default' => env('CACHE_STORE', 'database'),
            

.env

CACHE_STORE=redis
            

Possible options:

file
database
redis
array
memcached
            
***

config/session.php

Controls user sessions.

Location:

config/session.php

Example:

'driver' => env('SESSION_DRIVER', 'database'),
            

.env

SESSION_DRIVER=database
            

Available drivers:

file
database
redis
cookie
array

config/queue.php

Controls Laravel queues.

Location:

config/queue.php

Example:

'default' => env('QUEUE_CONNECTION', 'database'),
            

.env

QUEUE_CONNECTION=redis
            

Available drivers:

sync
database
redis
sqs

config/mail.php

Controls email sending.

Location:

config/mail.php

Example:

'default' => env('MAIL_MAILER'),
            

.env

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=test@gmail.com
MAIL_PASSWORD=password
            

Laravel uses these settings whenever it sends email.

config/filesystems.php

Controls file storage.

Location:

config/filesystems.php

Example:

'default' => env('FILESYSTEM_DISK', 'local'),
            

Available disks:

local
public
s3

Local Storage

FILESYSTEM_DISK=local
            

Files stored on the server.

Amazon S3

FILESYSTEM_DISK=s3
            

Files stored in AWS S3.

config/logging.php

Controls application logging.

Location:

config/logging.php

Example:

'default' => env('LOG_CHANNEL', 'stack'),
            

.env

LOG_CHANNEL=stack
            

Available channels:

single
daily
stack
slack
syslog

config/auth.php

Controls authentication settings.

Location:

config/auth.php

Defines:

  • Authentication guards
  • User providers
  • Password reset settings

Example:

'defaults' => [ 'guard' => 'web',]
            

config/services.php

Stores third-party service credentials.

Location:

config/services.php

Example:

'mailgun' => [
    'domain' => env('MAILGUN_DOMAIN'),
    'secret' => env('MAILGUN_SECRET'),
],
            

.env

MAILGUN_DOMAIN=example.com
MAILGUN_SECRET=xxxxxxxx
            

Used for:

  • Mailgun
  • Stripe
  • GitHub
  • Google
  • Facebook
  • Custom APIs

Defines where compiled Blade templates are stored.

Creating Your Own Configuration File

You can create custom configuration files.

Example:

config/payment.php

return [

    'currency' => 'USD',

    'tax' => 18,

];
            

Access values:

config('payment.currency');
            

Output:

USD

Configuration Caching

Laravel can cache all configuration files for faster performance.

Create cache:

php artisan config:cache
            

Clear cache:

php artisan config:clear
            

Why Use Config Cache?

Without cache:

Laravel reads many config files

With cache:

Laravel reads one optimized file

Result:

  • Faster application startup
  • Better production performance

Best Practices

✅ Store Sensitive Data in .env

Good:

DB_PASSWORD=secret
            

Bad:

'password' => 'secret'
            
***

✅ Use config() Helper

Good:

config('app.name');
            

Avoid:

env('APP_NAME');
            

outside configuration files.

✅ Cache Configuration in Production

php artisan config:cache
            

Summary

Laravel Configuration Files are the central place where application settings are stored. They live inside the config folder and control almost every aspect of your application.

The most important configuration files are:

File Purpose
app.php Application settings
database.php Database connections
cache.php Cache configuration
session.php Session management
queue.php Queue settings
mail.php Email configuration
auth.php Authentication
filesystems.php File storage
logging.php Logging
services.php Third-party APIs
view.php Blade view settings