Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TonsOfLaz's avatar

Cannot connect to default Homestead pgsql in Laravel 5.1

Has anyone been able to get their app to connect to the default Homestead postgres database in Laravel 5.1? I get the error message:

[PDOException]                                                                                                    
  SQLSTATE[08006] [7] FATAL:  no pg_hba.conf entry for host "192.168.10.1", user "homestead", database "homestead"  
  , SSL on                                                                                                          
  FATAL:  no pg_hba.conf entry for host "192.168.10.1", user "homestead", database "homestead", SSL off

Note that the IP is 192.168.10.1 rather than the one I entered in the .env file 192.168.10.10. Has anyone else been able to get this to work, or is this a bug?

My setup in the .env file is all the defaults,

APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomStringWith32Characters
DB_HOST=192.168.10.10
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
DB_CONNECTION=pgsql

And my pgsql connection entry has the standard stuff.

'host'     => env('DB_HOST', 'localhost'),
0 likes
12 replies
ELD's avatar

Try changing your DB_HOST to localhost. Since you're connecting to the Postgres SQL server from Homestead, you can access it via localhost. It looks like the pg_hba.conf has to be edited in order to allow non-localhost connections.

See if that works.

TonsOfLaz's avatar

Thanks for the reply @ELD .

I think the 192.168.10.10 was the recommended way to set up the .env file, but maybe not anymore.

When I change DB_HOST=192.168.10.10 to DB_HOST=localhost, I get a new error:

[PDOException]                                               
  SQLSTATE[08006] [7] FATAL:  role "homestead" does not exist  
ELD's avatar

@TonsOfLaz Looks like the user "homestead" doesn't exist. Try manually creating the user and see if that fixes the issue.

TonsOfLaz's avatar

Just to add more to the confusion, when I try to add the user role, I get that there are already three roles: homestead, postgres, and public.

I am going to try a completely fresh laravel install now, and restart the vagrant machine (even though this is where I started). I don't understand how the defaults for everything could not be connecting at all, or giving me error messages nobody else has seen.

TonsOfLaz's avatar

Ok, I did a fresh install using

laravel new postgrestest

I ran the php artisan key:generate to make the app actually work.

I updated my Homestead box using vagrant box update.

I changed and saved my .env file to read: (no changes except adding DB_CONNECTION)

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
DB_CONNECTION=pgsql

and I STILL get the error

[PDOException]                                               
  SQLSTATE[08006] [7] FATAL:  role "homestead" does not exist  

When I log into the connection through navicat, I see that there are three roles: homestead, postgres, and public. Does anyone have any guesses as to what might be going on here? Does this happen to other people?

Thanks in advance, I am really baffled here, its just a completely default installation of 5.1, trying to just use postgres in the way homestead was designed to use it. Nothing fancy.

ELD's avatar

@TonsOfLaz Are you still getting the error? I'll try it on my Homestead installation later tonight if you're still having trouble.

TonsOfLaz's avatar

Hi @ELD , I still haven't been able to set up any postgres db. Sorry for the delay getting back to you on this thread, please let me know if you end up trying it out! Thanks again

ELD's avatar

@TonsOfLaz I'll try it out later tonight and see what happens. I'll post back with an update.

ELD's avatar
ELD
Best Answer
Level 4

@TonsOfLaz So, just out of curiosity, have you tried logging in via the command line interface from within an SSH session on Homestead?

psql -U homestead -h localhost

I tried that on my Homestead installation and it worked fine. Here are the relevant portions of my .env file:

DB_CONNECTION=pgsql
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

Maybe check and see that your Homestead box is the latest version (homestead update) and then destroy and rebuild the VM to make sure that PostgresSQL is installed?

TonsOfLaz's avatar

@ELD Man, thanks again for following up on this. By SSHing into the vagrant box and running the artisan commands from inside the box rather than on the command line in the directory from my own machine, it finally worked!

Maybe this was one of those obvious times where everyone knows commands won't work unless you've SSHed into the box first, but everything else worked, and it worked using both sqlite and mysql DB_CONNECTION options.

So, to recap: If you are using DB_CONNECTION=pgsql and you try to run php artisan migrate or php artisan db:seed from your main command line, you will get an error message of:

[PDOException]                                               
  SQLSTATE[08006] [7] FATAL:  role "homestead" does not exist 

When this happens, you need to go to your homestead installation directory and type vagrant ssh. This will get you into the vagrant box. From there, you can verify that postgres sql is running with the command

psql -U homestead -h localhost

Once you have verified that, navigate to your app's directory and run artisan commands as normal, such as php artisan migrate and php artisan db:seed

Thanks to @ELD for debugging and explaining how he was able to make it work. Good luck to anyone else with this issue!

ELD's avatar

@TonsOfLaz Glad I could help you out. Sorry for taking so long to follow up on it. I forgot about it last night and decided to work on it this morning.

But yes, doing it inside the SSH connection of Homestead is what you need to do. You could also set it up to work outside of the SSH session by allowing PostgresSQL to connect to a host that isn't localhost. I don't know how to configure that off the top of my head, but you could try that out.

javedgardezi's avatar

Hi,

I am new to pgsql. I want to connect pgadmin (installed on my mac) to postgresql installed on homestead (this is also installed on same mac).

Please let me know the configuration details.

Kind regards, Javed Gardezi

Please or to participate in this conversation.