Consider the first rule in the pg_hba.conf:
local all all peer
It means that for all local connections, the Unix user should be the same as the db user. Obviously this is not the case for you php code, hence the failure Peer authentication failed for user....
The second rule would let your script connect, but it's ignored because the first rule takes precedence:
local all all trust
This rule means that all local connections are allowed without requiring password and without checking any identity.
If that's OK with you, just delete the first rule, and reload the postgresql service for the change to take effect.
The other rules should not be relevant to the problem since they're related to TCP connections, and according to the error message, that's not that the method used by your script, it's trying to connect through the default Unix domain socket.