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

Sturm's avatar
Level 5

Changing the default PostgreSQL port with Herd

I am attempting to run my existing Laravel 11 project with Herd on Windows. To avoid conflicting with a Docker PostgreSQL container already using port 5432, I set up the PostgreSQL service in Herd to use port 5433. I also changed the port number in the .env file to reflect that. I even opened up the postgresql.conf file in Herd's config directory, uncommented the port = line, changed it to 5433, and restarted the service afterward.

Although I can connect to the service perfectly fine using PhpStorm's database viewer (because I can specify the port number as 5433 with it), I still cannot run a simple php artisan migrate:fresh.

SQLSTATE[08006] [7] could not connect to server: Connection refused (0x0000274D/10061)
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432? (Connection: pgsql, SQL: select exists (select 1 from pg_class c, pg_namespace n where n.nspname = 'public' and c.relname = 'migrations' and c.relkind in ('r', 'p') and n.oid = c.relnamespace))

The port number must still be listed as 5432 somewhere in Herd, but I can't find it to change it. What am I missing?

0 likes
2 replies
RemiM's avatar
RemiM
Best Answer
Level 16
  1. Open config/database.php, locate the pgsql connection settings and make sure the port is set correctly.

  2. Clear the cache:

php artisan config:clear
php artisan cache:clear

Generally speaking, after any modification in the .envfile, you should clear the configuration cache.

1 like
Sturm's avatar
Level 5

Thank you, @remim!

I had already been performing an artisan optimize:clear after every change (just in case), but I forgot to mention that in my post.

I had just assumed that our project already had the 'port' line in config/database.php. This is yet another case of how making an assumption came back to bite me.

Thanks again for helping me with something that should have been obvious!

Please or to participate in this conversation.