By chance: Default error pages often contain detailed information, e.g.
Apache/{Version} ({OS}) {Modules} PHP/{Version} {Modules} Server at {Domain}
Not so easy: Find out which versions of PHP applications run on the server and which version of PHP they require.
Another approach, only mentioned for the sake of completeness; please forget after reading: You could (but you won't!) detect the PHP version by trying known exploits.