You can use something like fastCGI or patch php-fpm for versions up to 5.2.x
For versions PHP 5.3.x < 5.3.3 you can get php-fpm from the php svn like this;
cd php-5.3.x (download and unzip php first)
svn co http://svn.php.net/repository/php/php-src/trunk/sapi/fpm sapi/fpm
./configure --enable-fpm ...your other configure options, etc...
make && make install
- After that you need to adjust the default config file (installed into $prefix/etc) and run "php-fpm".
(Instructions from http://php-fpm.org/download/)
For php 5.3.3 and later php-fpm is included in the core. So the only thing you need to do is compile php with
--enable-fpm, se more here.
Set up the different versions you need in different paths, and start them.
Then you can point your webserver to use different running php-processes depending on which php version you need.