You can use my ppa, that I have created for this purpose. Please take notice of the pinning that is necessary. Also, aptitude will not recognize the pinning. You must use the aptitude specific method if you want to use it.
Note - this is for 10.04 (lucid) only
In case you really need to do it, use phpbrew.
My steps to install php5.3 on Ubuntu 16.04 (will work for 14.04):
Install phpbrew https://github.com/phpbrew/phpbrew/wiki/Quick-Start
To build 5.3.24 :
sudo phpbrew install 5.3.24 +bz2 +calendar +cli +gd +ctype +dom +iconv +fileinfo +filter +ipc +json +mbregex +mbstring +mhash +mcrypt +pcntl +pcre +pdo +phar +posix +readline +sockets +tokenizer +xml +curl +zip +mysql +debug +apxs2
/etc/apache2/mods-available/php5.load file must contain
LoadModule php5_module /usr/lib/apache2/modules/libphp5.3.24.so
AddType application/x-httpd-php .php
To enable module for apache2:
sudo a2dismod php5.6 ; sudo a2dismod php7.0 ; sudo a2enmod php5 ; sudo service apache2 restart
To install gd extension
phpbrew use php5.3.24
phpbrew ext install gd --with-gd=shared,/usr --enable-gd-native-ttf --with-gmp=shared,/usr --with-jpeg-dir=shared,/usr --with-xpm-dir=shared,/usr/X11R6 --with-png-dir=shared,/usr --with-freetype-dir=shared,/usr --with-vpx-dir=shared,/usr
Best Answer
Install PHP 5.2.17 on Ubuntu 14.04
Based on: http://www.rasyid.net/2014/10/07/using-multiple-php-inside-one-ubuntu-machine/Add PostgreSQL Apt Repository (provides postgresql-server-dev-9.4)
Install dependencies
Required to prevent an issue when compiling freetype support
Download PHP sources
Patch PHP
Compile and install