Updated June 2026. Tested on Laravel 13 and PHP 8.4.
Laravel keeps database setup simple. You rarely touch raw connection code. Instead you fill in a few values, and Eloquent and the query builder use them. This post is the map of how that works, with the driver specific guides linked from here.
Two files do the work
There are two places that matter.
.envholds the actual values for your machine: which driver, host, database name, username and password. This file is never committed, so each environment has its own.config/database.phpreads those.envvalues through theenv()helper and shapes them into named connections. You usually leave this file alone and just set the.env.
A typical .env database block looks like this.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=techalyst
DB_USERNAME=techalyst
DB_PASSWORD=secret
DB_CONNECTION picks which connection from config/database.php is the default. Everything else fills that connection in.
Drivers Laravel supports
Out of the box, Laravel's core supports five relational databases, each with a ready made connection in config/database.php.
- MySQL (and MariaDB)
- PostgreSQL
- SQLite
- SQL Server
Each one needs the matching PDO extension enabled in PHP, which is the part people miss. There is an official first party package for MongoDB too if you need a document database. The driver specific steps, including the gotchas for each, are in their own posts:
- Connecting to MySQL
- Connecting to PostgreSQL
- Connecting to SQL Server
- Connecting to SQLite
More than one connection
You are not limited to one database. config/database.php can hold as many named connections as you like, and you can point a model, a query or a migration at a specific one. That opens the door to read and write splitting, working with several databases at once, and a database per tenant. Those each have their own guide too.
So the whole thing comes down to this: set your .env, and Laravel reads config/database.php to build the connection. Pick the right driver guide above for the database you are using. Questions welcome in the comments.
All comments ()
No comments yet
Be the first to leave a comment on this post.