$ sudo apt-get install libfcgi-dev libfcgi0ldbl libjpeg62-dbg libmcrypt-dev libssl-dev libbz2-dev libjpeg-dev libfreetype6-dev libpng12-dev libxpm-dev libxml2-dev libpcre3-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libpng12-dev libxpm-dev libfreetype6-dev libmysqlclient-dev libt1-dev libgd2-xpm-dev libgmp-dev libsasl2-dev libmhash-dev unixodbc-dev freetds-dev libpspell-dev libsnmp-dev libtidy-dev libxslt1-dev libmcrypt-dev libdb5.3-dev devscripts libjson-c-dev
$ sudo apt-get build-dep php5
IMPORTANT NOTE: If you have error when try to install build dependences for php5 - fix it with hands(usually you should downgrade your packages).
$ wget http://museum.php.net/php5/php-5.6.2.tar.gz
$ tar xfz php-5.6.2.tar.gz
# cd php-5.6.2
# touch configure_it.sh
./configure \
--enable-fpm \
--with-mcrypt \
--enable-mbstring \
--with-openssl \
--with-mysql \
--with-mysql-sock \
--with-gd \
--with-jpeg-dir=/usr/lib \
--enable-gd-native-ttf \
--with-pdo-mysql \
--with-libxml-dir=/usr/lib \
--with-mysqli=/usr/bin/mysql_config \
--with-curl \
--enable-zip \
--enable-sockets \
--with-zlib \
--enable-exif \
--enable-ftp \
--with-iconv \
--with-gettext \
--enable-gd-native-ttf \
--with-t1lib=/usr \
--with-freetype-dir=/usr \
--prefix=/opt/php-5.6.2_zts \
--with-config-file-path=/opt/php-5.6.2_zts/etc \
--with-fpm-user=www-data \
--with-fpm-group=www-data \
--enable-maintainer-zts
$ nano configure_it.sh
$ chmod +x configure_it.sh
$ sudo mkdir /opt/php-5.6.2_zts
$ make
$ make test
$ make install
1. By default this PHP haven't php.ini file you must create and write it or copy from your another PHP installation.
2. If you want to run this PHP interpreter by default via "php" command you must run "update_alternatives":
$ sudo update-alternatives --install /usr/bin/php php /opt/php-5.6.2_zts/bin/php