DEV Community

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

Posted on

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

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