Although there are no PHP 5 packages for Debian 3.1 (aka "stable" or "sarge"), there are currently PHP 5 packages for "testing"/"etch" and "unstable"/"sid". Installation works the same way.
Also, the same process can be used for Ubuntu, but note that some of the packages may be in the "universe" section instead of "main".