Does anyone knows how do we force a php version to be installed when installing lamp via command line? For example I want to php5.1 when installing LAMP.
I don't think it is possible to install PHP 5.1 from repositories.
The PHP5 Launchpad page lists supported PHP versions starting from Hardy. 5.2.4 is the first supported version.
You might be able to install from untrusted repositories or compile from source.
But please note you are taking risks by not using a supported PHP version. The real solution would be to upgrade/fix the application instead of downgrading.