In your .env file add the following;
DB_CONNECTION=pgsql
Then all of the instructions that work for mysql should apply. Well most of them anyway.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello Please help me to create Laravel migration with postgreSQL. I searched in google for this, but didn't find a good solution. Anybody did Laravel migration with PostgreSQL? Please share link here. Thanks.
Either rename or make a copy of the existing ".env.example" to ".env"
Note! The values contained in the .env file is prepared for the Homestead box and should work with little modification if at all. However, if not using the Homestead VM but a Wamp or Xamp for example, you will need to provide the values specific to your environment.
There you will have the variable names actually used through out the framework. For example;
# Add this to change driver, the default is mysql
DB_CONNECTION=pgsql # or sqlite
# Add this if you are not using Homestead and you know the default pgsql port has not changed.
DB_PORT=5432
# Change the values to suit your environment if not on Homestead
DB_HOST=127.0.0.1
DB_DATABASE=homestead # or mainpagedb
DB_USERNAME=homestead # or postgres
DB_PASSWORD=secret # or postgres
# For the Schema you can add the following
DB_PGSQL_SCHEMA=fes
# then edit in 'config/database.php
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
// Notice the following has been modified
'schema' => env('DB_PGSQL_SCHEMA','public'),
],
You can create new environment variables (Key=>value) pairs and then call them elsewhere with env('Key', 'some default if key not set')
The easiest way to get started with Laravel is to use the Homestead Virtual Machine. However, using sqlite is equally as flexible to start. You can later switch to a different provider. For sqlite, just create an empty 'database/database.sqlite' file in the folder indicated.
Please or to participate in this conversation.