Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use postgreSQL in Laravel Homestead

I can do migration to my homestead. this is my .env

DB_CONNECTION=pgsql
DB_HOST=localhost
DB_PORT=54320
DB_DATABASE=intern
DB_USERNAME=homestead
DB_PASSWORD=secret

And I make a new server in my postgreSQL with

server name = Homestead,  
username = homestead,  
password = secret.  

then, I did migration and all the table created into my database(server=homestead)
The problem is, when I want to do login in my site. It occurs an error:

SQLSTATE[08006] [7] could not connect to server: Connection refused↵  
Is the server running on host "localhost" (::1) and accepting↵  
TCP/IP connections on port 54320?↵could not connect to server: Connection refused↵  
Is the server running on host "localhost" (127.0.0.1) and accepting↵  
TCP/IP connections on port 54320? (SQL: select * from "users" where "email" = [email protected] limit
like image 908
Saengdaet Avatar asked Oct 05 '17 09:10

Saengdaet


People also ask

Can I use Laravel with PostgreSQL?

Laravel supports Postgres out-of-the-box (although it suggests MySQL in its example configuration). In this section, you'll start a new Laravel project with the Authentication scaffolding. Then you'll configure it to use Postgres as a data store.

How connect PostgreSQL to Laravel?

Laravel makes connecting with Postgres databases and running queries extremely simple out of the box. The Postgres database configuration for your application is located at Laravel Project Root Folder, config/database. php . In this file you may define Postgres database connection for your Laravel Application.

How do I connect to Homestead database?

Connecting To Your Databases To connect to your MySQL or Postgres database from your main machine via Navicat or Sequel Pro, you should connect to 127.0. 0.1 and port 33060 (MySQL) or 54320 (Postgres). The username and password for both databases is homestead / secret .


2 Answers

You have an extra 0 at the end of your port. Change DB_PORT=54320 to DB_PORT=5432

like image 107
hutch Avatar answered Oct 26 '22 23:10

hutch


try to access your homestead with ssh.

i think u already change the password from the inside

from laravel documentation i think that config should work

or try this command after u change the config

php artisan config:cache and php artisan cache:clear

https://laravel.com/docs/5.6/homestead#connecting-to-databases

like image 24
Kira Katou Avatar answered Oct 26 '22 23:10

Kira Katou