Database Setup in Laravel

18. April 2016 Beginner, Laravel 4
Database Setup in Laravel

Here we ‘ll look at database setup for a laravel application. Actually there are 2 places where we can include our database setup details like database connection, database host, database port, database name, database username, database password.

Those 2 locations are :

  • .env file( located at root of the project /.env)
  • database.php (loacated at /config/database.php )


.env is created only in freshly installed application, it does not show up when you deploy it. If we want to deply along with .env file then we have remove .env in .gitignore file. By default the .env is in .gitignore as this .env file contains sensible information.

If we open .env file, it looks like

Double the learning and saving. Buy 1 Get 1 on premium e-degrees

So we can edit the details with our database settings there.


For setting up database using config file database.php, open database.php file located at /config/database.php


We can set the default database connection, and can edit the appropriate settings.


This is how Laravel makes connecting with databases extremely simple.Feel free to check previous posts on Laravel Application Structure and Installing Laravel Framework

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.