psql requires password to be entered which you can supply by creating a
or by setting the
PGPASSWORD environment variable (Not recommended as per docs)
Use of this environment variable is not recommended for security
reasons, as some operating systems allow non-root users to see process
environment variables via ps; instead consider using a password file
But for a quick check you can try adding
in your php code before the command.
From PHP Docs
If the output argument is present, then the specified array will be
filled with every line of output from the command. Trailing
whitespace, such as \n, is not included in this array. Note that if
the array already contains some elements, exec() will append to the
end of the array. If you do not want the function to append elements,
call unset() on the array before passing it to exec().
If the return_var argument is present along with the output
argument, then the return status of the executed command will be
written to this variable.
$ret variables for the output and status of the executed command.