Just upgraded to Mountain Lion, and wanted to make PHP work on the built-in version of Apache.
Probably the easiest way is to use the PHP packages from Liip (a Swiss web development company). It's as easy as running the command from their website and you can choose among PHP 5.3, 5.4, and 5.5. For example:
That way you can also always update to the newest version (that they support), but be careful to backup your custom settings first.
I'm using this installation on Snow Leopard and it works like a charm. On my machine (not sure whether they are the same on Mountain Lion), these paths are often of interest:
And what I did to make this up-to-date PHP version available in the command line with the command
Hope that helps.