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)?

aptitude command not found, i replaced with apt :wink:
On step 2 u can simplify with "apt install php5.6-cli php5.6-fpm php5.6-bcmath ...."

You're suggesting installing PHP5.6 to Debian 10 with a command (aptitude) which is not supported on Debian 10. It's simply apt and nothing else.

This is an improved set of commands which does what you wanted:

apt 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 &&
apt update &&
pecl install timezonedb zip &&
apt install libmcrypt-dev libreadline-dev mcrypt php-pear &&
apt install php5.6-{cli,fpm,bcmath,mysql,curl,gd,imagick,intl,mbstring,xmlrpc,xsl,dev,zip,soap,xml}