How Do You Troubleshoot the PHP Error “role is not permitted to log in” So Your Script Can Log into a Postgres Database?

Problem scenario
You are trying to use a .php script on the back end to connect to your PostgreSQL database.  However, you get an error like this when you try to run it:

'PHP Warning:  pg_connect(): Unable to connect to PostgreSQL server: FATAL:  role  "funuser" is not permitted to log in in /tmp/d.php on line 7'

How can your .php script log into the Postgres database?

The user must have the ability to log in.  Log into the PostgreSQL database.  Run this command (where "funuser" is the database role that is hardcoded in the PHP script for the login to work):

alter role funuser login;

Leave a comment

Your email address will not be published. Required fields are marked *