PostgreSQL is licensed under the BSD license, which you can read here:
http://www.postgresql.org/licence.html
While PHP is licensed under the PHP license, which you can read more about here:
http://www.php.net/license/
and here:
http://www.php.net/license/3_0.txt
Basically, they're both BSD style licenses, which means you can distribute just binaries, just source, or both, with no worries.
The Zend engine, which php runs on top of is licensed similarly, in terms of licensing, cost, and distribution.