DEV Community

Cover image for Connecting local postgresql database to laravel in Ubuntu
gerkibz
gerkibz

Posted on

6 3

Connecting local postgresql database to laravel in Ubuntu

Step 1.Install laravel:~

curl -s "https://laravel.build/example-app?with=mysql,redis" | bash
composer create-project laravel/laravel example-app
cd example-app
php artisan serve
Enter fullscreen mode Exit fullscreen mode

Step 2. Install postgesql:~

sudo apt install postgresql postgresql-contrib
Enter fullscreen mode Exit fullscreen mode

Step 3. In the config/database.php file set the default database as psql:~
default' => env('DB_CONNECTION', 'pgsql')`

Step 4. Create a database for your project:~


sudo -u postgres psql
sudo -u createdb database_name
sudo -u adduser Username

Step 5. To setup the path for the database, go to the .env file and setup:~


DB_CONNECTION=pgsq
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=database_name
DB_USERNAME=Username
DB_PASSWORD=password

Step 6. Start the server:~


sudo service postgresql-9.3 start

Step 7. Migrate the files:~


sudo service postgresql-9.3 start

For more information check on this project
https://github.com/EKivutha/clothes_e-commerce
For more postresql tricks check out
https://gist.github.com/Kartones/dd3ff5ec5ea238d4c546

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (1)

Collapse
 
fredhaegele profile image
fredhaegele • Edited

Why though? You can specify which flavor of SQL you want from the start, with the container already installed with the needed drivers with the command:

curl -s "https://laravel.build/example-app?with=pgsql" | bash

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay