Homestead: PostgreSQL

Created on 22 Apr 2020  路  2Comments  路  Source: laravel/homestead

Versions

  • Vagrant: 2.2.7
  • Provider: Virtualbox 6.1.6
  • Homestead: 10.7.0

Host operating system

OSX Catalina

Homestead.yaml

ip: "192.168.10.10"
memory: 2048
cpus: 2
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/code/web/laravel/project1
      to: /home/vagrant/project1
    - map: ~/code/web/laravel/biztrip
      to: /home/vagrant/biztrip

sites:
    - map: homestead.test
      to: /home/vagrant/project1/public
    - map: homestead.biztrip
      to: /home/vagrant/biztrip/public

databases:
    - homestead

features:
    - mariadb: false
    - ohmyzsh: false
    - webdriver: false

proxy:
    - http: http://companyproxy.domain.local:8080
    - https: http://companyproxy.domain.local:8080

Vagrant destroy & up output

[will edit this in]

Expected behavior

Set postgresql port and access system via web and CLI likewise.

Actual behavior

Setting the postgresql port in .env to 54320 as stated in https://laravel.com/docs/7.x/homestead#connecting-to-databases the

SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 54320?

Setting the port to the standard 5432 resolves this.
However, when using artisan CLI, e.g. php artisan migrate:fresh this happens:

SQLSTATE[08006] [7] could not connect to server: Connection refused
        Is the server running on host "127.0.0.1" and accepting
        TCP/IP connections on port 5432?

So I have to set the port every time depending on the whether I use CLI or access the system via web? This doesn't seem right and I'm guessing I misconfigured something somewhere.

Edit: When I ssh into the vagrant machine and execute the CLI command from e.g. /home/vagrant/biztrip it works fine with the port 5432. So either change the port every time or go through the extra steps of ssh'ing into the machine and using the CLI from there?

Steps to reproduce

As seen above

References

none, yet

Most helpful comment

Setting the postgresql port in .env to 54320 as stated in https://laravel.com/docs/7.x/homestead#connecting-to-databases the

You don't want to do this in your laravel code running on Homestead. The code runs in the vm so it needs to be set to 5432

Setting the port to the standard 5432 resolves this.

Correct, working as intended.

However, when using artisan CLI, e.g. php artisan migrate:fresh this happens:

Running artisan on your host PC, yes you will need to change the port to 54320 and then back to 5432 for the web to continue working. The solution here is to run artisan commands inside the VM from your project root.

All 2 comments

Setting the postgresql port in .env to 54320 as stated in https://laravel.com/docs/7.x/homestead#connecting-to-databases the

You don't want to do this in your laravel code running on Homestead. The code runs in the vm so it needs to be set to 5432

Setting the port to the standard 5432 resolves this.

Correct, working as intended.

However, when using artisan CLI, e.g. php artisan migrate:fresh this happens:

Running artisan on your host PC, yes you will need to change the port to 54320 and then back to 5432 for the web to continue working. The solution here is to run artisan commands inside the VM from your project root.

I see, thanks a lot for clearing this up!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Modelizer picture Modelizer  路  5Comments

mtpultz picture mtpultz  路  4Comments

Quix0r picture Quix0r  路  4Comments

alexdover picture alexdover  路  4Comments

pqt picture pqt  路  3Comments