I want to have both PHP 5.2.17 and PHP 5.3.5 installed on my Ubuntu machine and switch as per my necessity. How can I achieve this?
You can use a php version manager to achieve this. Different version managers are available like:
My favorite is phpbrew. Hope this helps.
You can run 2 different PHP versions at once, but it's not as easy as just apt-getting them. You need to run one seperately installed version and serve it up according to the settings in your apache config.
You can do this using fastcgi for example: basically what you are looking for is the config you see on this page. You add a different handler in your config based on the situation/port/domain you need. The trick, after installing both versions, is this step:
===from that page==
(don't be put of by the fact that the linked question is a big one with no accepted answer. The method should (and does) work fine, but the user forgot to use
a) Single apache instance can not run two different PHP versions simultaneously (at least as far as I know it).
b) Two different PHP versions can't be installed from packages as those will conflict (and try overwriting the same directories).
for b) Compile „the other” PHP version from source, manually (or if you prefer, grab source of appropriate package and modify it to avoid conflicts and to modify install paths)
for a) Create separate set of configs for apache with different module paths and separate startup script. And of course run it on separate port.
I guess that will do what you need!
You can also run each website with diferentes users. More secure.
I used this aproach one time.
Now i think it is better to use php-fpm... but it is a litle more complicated to configure multiple php versions.
Will need to run multiples php-fpms and set apache to use each other.
I hope this helps!
If you want to run them at the same time, you need two different ports. Maybe you can just change your apache config (httpd.conf) with a simple script that moves one or another version into the correct position before starting apache.