Laravel Configuration Guide

When we install Laravel, the very next step is always configuration. Without setting up properly, your app will not run on server, mail will not send, and database may not connect. In this article, I will explain Laravel configuration in simple words with real examples.


Laravel Configuration Basics

Laravel has a special folder called config/. Inside this folder, there are many files like app.php, database.php, cache.php, mail.php. These are the Laravel config files that control how your application works.

You can also use the .env file for environment settings. The .env file in Laravel is used to store credentials like database username, password, API keys.


Apache Laravel Configuration

If you are hosting Laravel on Apache, you need to configure Apache properly. Common steps:

  1. Enable mod_rewrite in Apache.

  2. Point your document root to the public/ folder of Laravel.

  3. Create a virtual host configuration file.

So if you see laravel apache configuration, it means making sure Apache knows where Laravel is installed.


Laravel Configure Database

Database setup is always needed. In Laravel, you can configure database using .env file. For example:

 
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel //your database name
DB_USERNAME=root DB_PASSWORD=

This is called laravel configure database connection. If it is not set correctly, you may see errors like laravel database not configured.


Laravel Mail Configuration

Laravel supports many ways to send emails. You can use SMTP configuration or Mailgun  in Laravel.

Laravel SMTP Configuration Example

In .env file:

 
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your_email@gmail.com MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=your_email@gmail.com MAIL_FROM_NAME="${APP_NAME}"

This is known as laravel smtp configuration. For Gmail, you write gmail smtp configuration laravel. For Mailgun, you write mailgun laravel configuration.

There is also laravel dynamic mail configuration where you can change mail settings at runtime.


Laravel Server Configuration

If you are deploying Laravel on a server, you must do Laravel server configuration:

  • Apache or Nginx setup

  • PHP version update (php.ini configuration for Laravel sometimes needed)

  • Correct file permissions for storage and bootstrap/cache

This ensures Laravel runs smoothly in production.


Laravel CORS Configuration

From Laravel 12 onwards, many developers ask about laravel 12 cors configuration. CORS means Cross-Origin Resource Sharing. It is used when your API is requested from another domain. Laravel has built-in middleware to handle CORS, and you can configure it in config/cors.php.


Laravel Cache and Clear Cache

Many times, after changing config, it doesn’t work immediately. This happens because of caching.

Common Artisan commands:

  • php artisan config:cache → cache all config files

  • php artisan config:clear → clear cached config

  • php artisan cache:clear → clear application cache

  • php artisan route:clear → clear route cache

  • php artisan view:clear → clear compiled views

Always remember to clear all laravel cache when changes don’t reflect.


Laravel Custom Config File

Sometimes, default config files are not enough. You can create your own.

Steps to create config file in Laravel:

  1. Create a file inside config/, e.g. config/custom.php.

  2. Add your settings as an array.

  3. Access them in code with config('custom.key').


.env File in Laravel

The .env file in Laravel is very important. It stores environment-specific values.

How to Generate Env File in Laravel?

Just copy .env.example and rename it to .env.

How to Configure Env File?

Open .env and add your settings like DB, mail, app name. 

How to Protect .env File in Laravel?

Make sure your server does not expose .env file to public. In Apache/Nginx config, block direct access. Never commit .env to GitHub.


Laravel PHP ini Configuration

Sometimes Laravel needs changes in php.ini. For example, to increase file upload size or memory limit. This is also part of laravel php ini configuration.


Laravel SQL Server Configuration

If you are not using MySQL but SQL Server, you can configure it in .env:

 
DB_CONNECTION=sqlsrv 
DB_HOST=127.0.0.1
DB_PORT=1433
DB_DATABASE=laravel
DB_USERNAME=sa
DB_PASSWORD=your_password

This is called laravel sql server configuration.


Final Words

So that is all about Laravel configuration. We learned about Apache Laravel configuration, Laravel configure database, Laravel sendmail configuration, Laravel SMTP configuration, and even how to clear Laravel cache when things don’t work. We also checked Laravel custom config file, env file in Laravel, and Laravel server configuration.

If you follow these steps carefully, your Laravel project will be ready for local and production server without errors.