DEV Community

Vincent Tommi
Vincent Tommi

Posted on

Understanding the Laravel `config` Folder: What I'm Learning as a Beginner

I'm currently learning Laravel, and one of the things that caught my attention was the config folder.

Coming from a backend development background, I wanted to understand what all those PHP files were doing instead of simply knowing that they "contain configuration."

When I opened a fresh Laravel project, I found files like:

config/
├── app.php
├── auth.php
├── broadcasting.php
├── cache.php
├── concurrency.php
├── cors.php
├── database.php
├── filesystems.php
├── hashing.php
├── images.php
├── logging.php
├── mail.php
├── queue.php
├── services.php
├── session.php
└── view.php
Enter fullscreen mode Exit fullscreen mode

At first, it looked like a lot to understand.

So I decided to go through them one by one and document what I'm learning. Hopefully, this can also help someone else who is starting with Laravel.

Note: The exact configuration files can vary depending on your Laravel version and the packages installed in your application.


What is the config folder?

The config directory contains PHP configuration files that control different parts of your Laravel application.

You can think of it as the place where Laravel learns things like:

  • How to connect to a database
  • How authentication works
  • How files are stored
  • How emails are sent
  • How caching works
  • How sessions work
  • How queues work
  • How logging works
  • How external services are configured

The structure looks roughly like:

Laravel Application
        |
        ↓
     config/
        |
   ┌────┼────┬────┬────┐
   ↓    ↓    ↓    ↓    ↓
  DB   Auth  Mail Cache Logging
Enter fullscreen mode Exit fullscreen mode

1. app.php

app.php contains general configuration for your Laravel application.

For example:

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

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

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

    'url' => env('APP_URL', 'http://localhost'),

    'timezone' => 'UTC',

    'locale' => 'en',
];
Enter fullscreen mode Exit fullscreen mode

It can contain settings related to:

  • Application name
  • Environment
  • Debug mode
  • Application URL
  • Timezone
  • Locale
  • Encryption
  • Service providers

For example, in .env:

APP_NAME=MyApplication
Enter fullscreen mode Exit fullscreen mode

Laravel can retrieve that value using:

env('APP_NAME')
Enter fullscreen mode Exit fullscreen mode

My understanding

I think of app.php as:

General settings for the Laravel application.


2. auth.php

The auth.php file deals with authentication.

Authentication is basically answering the question:

Who is this user?

This configuration can define things such as:

  • Authentication guards
  • User providers
  • User models
  • Password reset configuration

For example:

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\Models\User::class,
    ],
],
Enter fullscreen mode Exit fullscreen mode

This tells Laravel which model it should use when working with users.

For example:

User
  ↓
Login
  ↓
Authentication
  ↓
Authenticated request
Enter fullscreen mode Exit fullscreen mode

My understanding

I think of auth.php as:

How Laravel identifies and authenticates users.


3. broadcasting.php

The broadcasting.php file is related to real-time events.

Broadcasting allows Laravel to send events from the server to clients in real time.

For example, imagine a chat application:

User A sends message
        ↓
Laravel
        ↓
Broadcast event
        ↓
User B receives message
Enter fullscreen mode Exit fullscreen mode

This can be useful for:

  • Chat applications
  • Real-time notifications
  • Live dashboards
  • Real-time status updates

If you're building a simple CRUD API, you may not need to work with this configuration immediately.

My understanding

I think of broadcasting.php as:

Configuration for sending Laravel events to clients in real time.


4. cache.php

The cache.php file controls Laravel's caching system.

Caching allows your application to temporarily store data so that it doesn't have to perform the same expensive operation repeatedly.

For example:

Cache::put('username', 'Vincent', 3600);
Enter fullscreen mode Exit fullscreen mode

Laravel can work with different cache stores depending on your configuration.

Examples include:

  • File
  • Database
  • Redis
  • Array

For example:

CACHE_STORE=redis
Enter fullscreen mode Exit fullscreen mode

My understanding

I think of cache.php as:

Where and how Laravel stores cached data.


5. concurrency.php

The concurrency.php file is related to Laravel's concurrency features.

Concurrency is about allowing multiple tasks to execute without unnecessarily waiting for each one to finish before starting the next.

For example:

Without concurrency:

Task A → Task B → Task C
Enter fullscreen mode Exit fullscreen mode

With concurrency:

Task A ─┐
Task B ─┼──→ Results
Task C ─┘
Enter fullscreen mode Exit fullscreen mode

This can be useful when an application needs to perform several independent operations.

As I'm learning Laravel, this is one of the configuration files I'm treating as something to understand later rather than something I need to modify immediately.

My understanding

I think of concurrency.php as:

Configuration related to running multiple operations concurrently.


6. cors.php

CORS stands for Cross-Origin Resource Sharing.

This becomes especially important when you're building a separate frontend and backend.

For example:

Frontend
Next.js
http://localhost:3000

        ↓ API request

Backend
Laravel
http://localhost:8000
Enter fullscreen mode Exit fullscreen mode

These are different origins.

The browser needs to know whether the frontend is allowed to communicate with the backend.

The CORS configuration deals with things such as:

  • Allowed origins
  • Allowed HTTP methods
  • Allowed headers
  • Credentials

For an API, this is particularly important.

My understanding

I think of cors.php as:

Configuration that controls which origins are allowed to communicate with my Laravel application.


7. database.php

This is one of the configuration files I'm paying the most attention to because I recently connected Laravel to PostgreSQL.

The database.php file controls Laravel's database connections.

For example, a PostgreSQL connection may look like:

'pgsql' => [
    'driver' => 'pgsql',
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '5432'),
    'database' => env('DB_DATABASE', 'laravel'),
    'username' => env('DB_USERNAME', 'root'),
    'password' => env('DB_PASSWORD', ''),
],
Enter fullscreen mode Exit fullscreen mode

The actual values can come from .env:

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=laravel
DB_USERNAME=laravel_user
DB_PASSWORD=your_password
Enter fullscreen mode Exit fullscreen mode

The relationship can be understood like this:

.env
 ↓
config/database.php
 ↓
Laravel database layer
 ↓
PostgreSQL
Enter fullscreen mode Exit fullscreen mode

My understanding

I think of database.php as:

How Laravel connects to and communicates with databases.


8. filesystems.php

This file controls Laravel's file storage.

Imagine an application where users can upload:

  • Profile pictures
  • Documents
  • PDFs
  • Product images
  • Videos

Laravel needs to know where those files should be stored.

For example:

Storage::put('documents/example.pdf', $file);
Enter fullscreen mode Exit fullscreen mode

The filesystem configuration determines which storage disk Laravel uses.

My understanding

I think of filesystems.php as:

Where and how Laravel stores files.


9. hashing.php

The hashing.php file controls Laravel's hashing configuration.

Hashing is particularly important when dealing with passwords.

You should never store passwords as plain text:

password123
Enter fullscreen mode Exit fullscreen mode

Instead, the password is hashed before being stored:

password123
      ↓
    Hash
      ↓
   Database
Enter fullscreen mode Exit fullscreen mode

Laravel supports hashing algorithms such as:

  • Bcrypt
  • Argon
  • Argon2id

My understanding

I think of hashing.php as:

How Laravel hashes sensitive data such as passwords.


10. images.php

The images.php configuration file is related to image handling and processing.

This can become useful when an application needs to work with uploaded images.

For example:

  • Resizing images
  • Processing images
  • Optimizing images
  • Converting images

This might be useful in applications such as e-commerce platforms where users upload product images.

My understanding

I think of images.php as:

Configuration related to image processing.


11. logging.php

The logging.php file controls Laravel's logging system.

Logs are extremely useful when debugging an application.

Laravel can write logs to files such as:

storage/logs/laravel.log
Enter fullscreen mode Exit fullscreen mode

You can also create your own logs:

Log::info('User registered successfully');
Enter fullscreen mode Exit fullscreen mode

Or:

Log::error('Payment failed');
Enter fullscreen mode Exit fullscreen mode

Laravel supports different logging channels.

My understanding

I think of logging.php as:

How Laravel records application events, warnings, and errors.

When debugging Laravel applications, I'll probably spend quite a lot of time looking at:

storage/logs/laravel.log
Enter fullscreen mode Exit fullscreen mode

12. mail.php

The mail.php file controls email configuration.

Laravel applications commonly need to send emails for things such as:

  • Password resets
  • Email verification
  • Booking confirmations
  • Payment receipts
  • Notifications

For example, .env might contain:

MAIL_MAILER=smtp
MAIL_HOST=smtp.example.com
MAIL_PORT=587
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
Enter fullscreen mode Exit fullscreen mode

Laravel uses the mail configuration to determine how emails should be sent.

My understanding

I think of mail.php as:

How Laravel sends emails.


13. queue.php

The queue.php file controls Laravel's queue system.

Queues are useful for tasks that don't need to happen before the user receives a response.

For example, sending an email could be handled in the background:

User registers
      ↓
Laravel creates account
      ↓
Email job added to queue
      ↓
Response returned
      ↓
Queue worker sends email
Enter fullscreen mode Exit fullscreen mode

Instead of:

User registers
      ↓
Create account
      ↓
Send email
      ↓
Wait...
      ↓
Return response
Enter fullscreen mode Exit fullscreen mode

Queues can improve application responsiveness.

My understanding

I think of queue.php as:

How Laravel handles background jobs.


14. services.php

The services.php file is commonly used for third-party services.

For example:

  • GitHub
  • Google
  • Stripe
  • PayPal
  • AWS
  • External APIs

You might have configuration like:

'github' => [
    'client_id' => env('GITHUB_CLIENT_ID'),
    'client_secret' => env('GITHUB_CLIENT_SECRET'),
    'redirect' => env('GITHUB_REDIRECT_URI'),
],
Enter fullscreen mode Exit fullscreen mode

The actual credentials would normally be stored in .env:

GITHUB_CLIENT_ID=your_client_id
GITHUB_CLIENT_SECRET=your_client_secret
GITHUB_REDIRECT_URI=http://localhost:8000/auth/github/callback
Enter fullscreen mode Exit fullscreen mode

My understanding

I think of services.php as:

Configuration for services outside the Laravel application.


15. session.php

The session.php file controls Laravel's session management.

Sessions allow an application to remember information between HTTP requests.

For example:

User logs in
     ↓
Session created
     ↓
User visits another page
     ↓
Laravel knows the user
Enter fullscreen mode Exit fullscreen mode

Laravel can store sessions using different drivers.

For example:

SESSION_DRIVER=file
Enter fullscreen mode Exit fullscreen mode

or:

SESSION_DRIVER=database
Enter fullscreen mode Exit fullscreen mode

My understanding

I think of session.php as:

How Laravel stores and manages user sessions.


16. view.php

The view.php file contains configuration related to Laravel's views.

Laravel's traditional server-side frontend system uses Blade templates.

For example:

resources/
└── views/
    ├── welcome.blade.php
    └── dashboard.blade.php
Enter fullscreen mode Exit fullscreen mode

The view configuration helps Laravel locate and work with these templates.

If you're building a Laravel API without Blade, you may not interact with this file very often.

My understanding

I think of view.php as:

Configuration for Laravel's view system.


Which Configuration Files Should I Learn First?

As someone learning Laravel from a backend development perspective, I'm not trying to memorize everything at once.

I'd prioritize them like this:

Learn first

app.php
auth.php
database.php
hashing.php
logging.php
services.php
Enter fullscreen mode Exit fullscreen mode

Then:

cache.php
cors.php
queue.php
session.php
Enter fullscreen mode Exit fullscreen mode

And later:

broadcasting.php
concurrency.php
filesystems.php
images.php
mail.php
view.php
Enter fullscreen mode Exit fullscreen mode

This doesn't mean the second group is less important. It just means you don't need to understand every Laravel feature on day one.


.env vs config

This was one of the most important things for me to understand.

Laravel has a .env file:

.env
Enter fullscreen mode Exit fullscreen mode

and a configuration directory:

config/
Enter fullscreen mode Exit fullscreen mode

They work together, but they have different purposes.

For example, .env might contain:

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=laravel
DB_USERNAME=laravel_user
DB_PASSWORD=your_password
Enter fullscreen mode Exit fullscreen mode

Then config/database.php reads those values:

'pgsql' => [
    'driver' => 'pgsql',
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '5432'),
    'database' => env('DB_DATABASE', 'laravel'),
    'username' => env('DB_USERNAME', 'root'),
    'password' => env('DB_PASSWORD', ''),
],
Enter fullscreen mode Exit fullscreen mode

So I think of it like this:

.env
  ↓
Environment-specific values
  ↓
config/*.php
  ↓
Laravel configuration
  ↓
Laravel application
Enter fullscreen mode Exit fullscreen mode

env() vs config()

You'll see these two functions frequently when working with Laravel.

env()

env() reads environment variables.

For example:

APP_NAME=MyApplication
Enter fullscreen mode Exit fullscreen mode

You can access it with:

env('APP_NAME')
Enter fullscreen mode Exit fullscreen mode

config()

config() reads Laravel's configuration.

For example:

config('app.name')
Enter fullscreen mode Exit fullscreen mode

This can retrieve the application name configured in config/app.php.

A useful rule I'm learning is:

Use env() mainly inside configuration files, and use config() in application code.

For example, in application code, prefer:

config('app.timezone')
Enter fullscreen mode Exit fullscreen mode

rather than repeatedly accessing:

env('APP_TIMEZONE')
Enter fullscreen mode Exit fullscreen mode

Why php artisan config:clear Is Important

While setting up PostgreSQL, I ran into a situation where Laravel wasn't using the database configuration I expected.

One command I learned about was:

php artisan config:clear
Enter fullscreen mode Exit fullscreen mode

This clears Laravel's cached configuration.

Laravel can cache configuration to improve performance, especially in production.

If you change your .env file and Laravel appears to be ignoring your changes, you can try:

php artisan config:clear
Enter fullscreen mode Exit fullscreen mode

Then test your application again.

You can also rebuild the configuration cache with:

php artisan config:cache
Enter fullscreen mode Exit fullscreen mode

A Simple Way to Remember the Files

Here's how I'm currently thinking about the configuration files:

File What it controls
app.php General application settings
auth.php Authentication
broadcasting.php Real-time events
cache.php Caching
concurrency.php Concurrent execution
cors.php Cross-origin requests
database.php Database connections
filesystems.php File storage
hashing.php Password/data hashing
images.php Image processing
logging.php Application logging
mail.php Email
queue.php Background jobs
services.php Third-party services
session.php Sessions
view.php Blade views

Coming From Django?

Since I also work with Django, comparing Laravel with Django helps me understand the concepts.

The two frameworks aren't identical, but there are some useful similarities:

Laravel Django
.env Environment variables / .env
config/app.php settings.py
config/database.php DATABASES
config/auth.php Authentication configuration
config/filesystems.php Media/storage configuration
config/mail.php Email settings
config/cache.php CACHES
config/logging.php LOGGING
config/session.php Session configuration

Coming from Django, this comparison makes Laravel's structure a little easier for me to understand.


Final Thoughts

I'm learning that I don't need to understand every Laravel configuration file immediately.

The important thing is to understand why the files exist and when I might need them.

For backend development, the configuration files I'll probably interact with most often are:

database.php
auth.php
app.php
cors.php
logging.php
queue.php
cache.php
services.php
Enter fullscreen mode Exit fullscreen mode

The more I build applications with Laravel, the more these configurations will start making sense through practical use.

I'm sharing this as part of my Laravel learning journey. If you're also learning Laravel, hopefully this gives you a simple starting point for understanding what's inside the config directory.

And if I've misunderstood anything, feel free to correct me in the comments. That's part of learning.

Top comments (0)