I want to both keep the latest PHP provided with Ubuntu and to have a specific PHP version installed somewhere. Is it doable? Can I just compile the PHP in some folder and then somewhere in Apache configs (I mean the apache provided with Ubuntu) switch between PHP dirs when needed.
Yes, you can. Fisrt compile & install new php, and then define your new php as a cgi module to apache. open apache config file and add this lines
or you may system wide define new extension