How do I install PHP 5.6 (for a legacy software) to Debian 10?

Step 1

aptitude install apt-transport-https lsb-release ca-certificates &&
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg &&
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" >> /etc/apt/sources.list &&
aptitude update

Step 2

aptitude install php5.6-cli
aptitude install php5.6-fpm
aptitude install php5.6-bcmath
aptitude install php5.6-mysql
aptitude install php5.6-curl
aptitude install php5.6-gd
aptitude install php5.6-imagick
aptitude install php5.6-intl
aptitude install php5.6-mbstring
aptitude install php5.6-xmlrpc
aptitude install php5.6-xsl
aptitude install php5.6-dev
aptitude install zip php5.6-zip
aptitude install php-pear
aptitude install php5.6-soap
aptitude install php5.6-xml
pecl install timezonedb
aptitude install libmcrypt-dev libreadline-dev
aptitude install mcrypt
aptitude install php5.6-mcrypt

How to fix «mcrypt.h not found. Please reinstall libmcrypt» in Debian 9?

Step 3

rm -rf /etc/php/5.6/cli &&
ln -s /etc/php/5.6/fpm /etc/php/5.6/cli &&
/etc/init.d/php5.6-fpm restart

See also: How do I install PHP 7.2 FPM and CLI for Magento 2 to Debian 9 (Stretch)?