php-fpm have to be installed for all needed versions

Create .htaccess in document root

insert code in it at the top:

<FilesMatch ".(php4|php5|php3|php2|php|phtml)$">

# From the Apache version 2.4.10 and above, use the SetHandler to run PHP as a fastCGI process server

SetHandler "proxy:unix:/run/php/php7.1-fpm.sock|fcgi://localhost"

</FilesMatch>