The simplest way to avoid these issues is of course to try to update the software/scripts. I haven’t gone through all the changelogs from PHP 5.2 to 5.5 though I doubt a lot of changes are necessary in order to make it work with the latest version.
In case you still prefer/have to use the old versions, then you have two options:
a) Remove the current PHP/MySQL packages, locate the old versions as .deb files, install them using dpkg -i and use apt-mark hold package-name in order to avoid updates from being installed
b) Compile/download the PHP/MySQL binaries and install them manually
When it comes to the first option, you may end up having a lot of dependency problems and having to downgrade other packages. Therefore, I recommend that you stick to the second option unless you have never tried to compile a package before.